Вопрос

I have worked with Core Data using document based apps. But know, I'm trying to build an app similar the Notes app on the Mac OS X. So I've created a non-document based app with a Data Model. I binded the values exactly the same way that I was doing the same way with my previous Core Data apps.

My arrayController is set to Entity Mode with the name of my entity, its Prepares Contents is checked and it's ManagedObjectContext is bonded to File's Owner's managedObjectContext. That's exactly what I was doing in my previous apps. But with these bindings, I have the following error :

[<NSApplication 0x101a032c0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key managedObjectContext.
(
0   CoreFoundation                      0x00007fff96525b06 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff915563f0 objc_exception_throw + 43
2   CoreFoundation                      0x00007fff965b9f49 -[NSException raise] + 9
3   Foundation                          0x00007fff91e518bc -      [NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 238
4   Foundation                          0x00007fff91d99539 -  [NSObject(NSKeyValueCoding) valueForKey:] + 400
5   AppKit                              0x00007fff8f41a6fb -  [NSApplication(NSScripting) valueForKey:] + 514
6   Foundation                          0x00007fff91db9de8 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 341
7   AppKit                              0x00007fff8f6580d4 -[NSBinder valueForBinding:resolveMarkersToPlaceholders:] + 163
8   AppKit                              0x00007fff8f665a13 -[NSObjectParameterBinder _updateObject:observedController:observedKeyPath:context:] + 1046
9   AppKit                              0x00007fff8f64f6c9 -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 641
10  AppKit                              0x00007fff8f4d80ca -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1012
11  AppKit                              0x00007fff8f4b714d loadNib + 317
12  AppKit                              0x00007fff8f4b6679 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
13  AppKit                              0x00007fff8f4b64ae -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 200
14  AppKit                              0x00007fff8f4b628e +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 360
15  AppKit                              0x00007fff8f4b2a2f NSApplicationMain + 398
16  Secrets                             0x0000000100000ea2 main + 34
17  libdyld.dylib                       0x00007fff920927e1 start + 0
18  ???                                 0x0000000000000003 0x0 + 3
)
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSApplication 0x101a032c0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key managedObjectContext.'
*** First throw call stack:
(
0   CoreFoundation                      0x00007fff96525b06 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff915563f0 objc_exception_throw + 43
2   CoreFoundation                      0x00007fff965b9f49 -[NSException raise] + 9
3   Foundation                          0x00007fff91e518bc -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 238
4   Foundation                          0x00007fff91d99539 -[NSObject(NSKeyValueCoding) valueForKey:] + 400
5   AppKit                              0x00007fff8f41a6fb -[NSApplication(NSScripting) valueForKey:] + 514
6   Foundation                          0x00007fff91db9de8 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 341
7   AppKit                              0x00007fff8f6580d4 -[NSBinder valueForBinding:resolveMarkersToPlaceholders:] + 163
8   AppKit                              0x00007fff8f665a13 -[NSObjectParameterBinder _updateObject:observedController:observedKeyPath:context:] + 1046
9   AppKit                              0x00007fff8f64f6c9 -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 641
10  AppKit                              0x00007fff8f4d80ca -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1012
11  AppKit                              0x00007fff8f4b714d loadNib + 317
12  AppKit                              0x00007fff8f4b6679 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
13  AppKit                              0x00007fff8f4b64ae -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 200
14  AppKit                              0x00007fff8f4b628e +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 360
15  AppKit                              0x00007fff8f4b2a2f NSApplicationMain + 398
16  Secrets                             0x0000000100000ea2 main + 34
17  libdyld.dylib                       0x00007fff920927e1 start + 0
18  ???                                 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminate called throwing an exception

What am I doing wrong?

Это было полезно?

Решение

this class is not key value coding-compliant for the key managedObjectContext

That tells you exactly what's wrong. You bound the managed object context to File's Owner, but File's Owner apparently doesn't have a managed object context.

Другие советы

If anyone else finds this and is looking for a more thorough answer like I was, have a look at the Apple Developer Documentation. This FAQ states the following:

Where a managed object context comes from is entirely application-dependent. In a Cocoa document-based application using NSPersistentDocument, the persistent document typically creates the context, and gives you access to it through the managedObjectContext method.

In a single-window application, if you create your project using the standard project assistant, the application delegate (the instance of the AppDelegate class) again creates the context, and gives you access to it through the managedObjectContext method. In this case, however, the code to create the context (and the rest of the Core Data stack) is explicit. It is written for you automatically as part of the template.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top