问题
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 -
- What is the correct way of using NSManagedObjectContext proxy in interface builder library?
- 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