Unable to use Managed Object Context proxy from Interface builder library

末鹿安然 提交于 2020-01-06 14:21:11

问题


I am making a simple mac os x app, in which I will be showing some records in a table view, after retrieving those from local db. I am using core data and NSArrayController proxy for the same and I am trying to achieve it through cocoa-bindings.

Now I can easily make it working, by performing this binding in NSArrayController proxy:

Proxy: NSArrayController
Parameters: Managed Object Context
Bind to: App Delegate
Model Key Path: self.managedObjectContext

but I am trying to use NSManagedObjectContext proxy from Interface builder library, for this binding:

Proxy: NSArrayController
Parameters: Managed Object Context
Bind to: Managed Object Context
Model Key Path: self

I am surprised that there is no binding available for it, in bindings pan. At least there should be a binding to map persistent store coordinator to it.

To assign MOC a persistent store coordinator, I am using below code:

@property (strong) IBOutlet NSManagedObjectContext *listManagedObjectContext;

[self.listManagedObjectContext setPersistentStoreCoordinator:[NSAppDelegate persistentStoreCoordinator]];

Problem is -

I am continuously getting this message in console:

Cannot perform operation since managed object context has no persistent store coordinator

With this stack backtrace:

0   CoreFoundation                      0x00007fff8b59fb06 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff881103f0 objc_exception_throw + 43
2   CoreFoundation                      0x00007fff8b59f8dc +[NSException raise:format:] + 204
3   AppKit                              0x00007fff907eb5e6 -[_NSManagedProxy _persistentStoreCoordinator] + 81
4   AppKit                              0x00007fff907eb528 -[_NSManagedProxy _entity] + 49
5   AppKit                              0x00007fff907eb43a -[_NSManagedProxy fetchRequestWithSortDescriptors:limit:] + 95
6   AppKit                              0x00007fff90cc04f0 -[NSObjectController(NSManagedController) _executeFetch:didCommitSuccessfully:actionSender:] + 73

My questions are -

  1. What is the correct way of using NSManagedObjectContext proxy in interface builder library?
  2. How can I resolve observed problem? Please suggest.

回答1:


Resolved this problem, by using this code:

- (void)awakeFromNib
{
    [self.listManagedObjectContext setPersistentStoreCoordinator:[NSAppDelegate persistentStoreCoordinator]];
}


来源:https://stackoverflow.com/questions/20180939/unable-to-use-managed-object-context-proxy-from-interface-builder-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!