Error: Employee not KVC comliant for key "manager"


#1

I am getting the error below when I try to update an employee. If I understand what it’s saying, it’s trying to set the “manager’” key of an employee class. I can’t figure out why it would be happening.

It happens in -addEmployeesObject in Department.m on the call for didChangeValueForKey…
[self didChangeValueForKey:@“employees” withSetMutation:NSKeyValueUnionSetMutation usingObjects:s];

If anybody is able to help, I’d be greatly appreciate it I’d really like to understand this.

2012-01-10 22:45:50.522 Departments[10542:707] Error setting value for key path firstName of object <Employee: 0x1001ac520> (entity: Employee; id: 0x1004505f0 x-coredata://11E13B18-59C7-417F-A860-A863C6450697/Employee/p2 ; data: {
department = “0x100450570 x-coredata://11E13B18-59C7-417F-A860-A863C6450697/Department/p1”;
firstName = D;
lastName = nil;
}) (from bound object <NSTableColumn: 0x10042eb70> identifier: (null)): [<Employee 0x1001ac520> valueForUndefinedKey:]: the entity Employee is not key value coding-compliant for the key “manager”.
2012-01-10 22:45:50.524 Departments[10542:707] (
0 CoreFoundation 0x00007fff896b4286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff9071dd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff896b40ba +[NSException raise:format:arguments:] + 106
3 AppKit 0x00007fff8e5c15c5 -[NSBinder _setValue:forKeyPath:ofObject:mode:validateImmediately:raisesForNotApplicableKeys:error:] + 893
4 AppKit 0x00007fff8e5c0002 -[NSBinder setValue:forBinding:atIndex:error:] + 302
5 AppKit 0x00007fff8e9a5571 -[_NSValueBinderPlugin applyObjectValue:forBinding:operation:needToRunAlert:error:] + 248
6 AppKit 0x00007fff8e95ee78 -[NSValueBinder _applyObjectValue:forBinding:canRecoverFromErrors:handleErrors:typeOfAlert:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:] + 108
7 AppKit 0x00007fff8e95eb6f -[NSValueBinder applyDisplayedValueHandleErrors:typeOfAlert:canRecoverFromErrors:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:error:] + 591
8 AppKit 0x00007fff8e95e902 -[NSValueBinder _applyDisplayedValueIfHasUncommittedChangesWithHandleErrors:typeOfAlert:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:error:] + 154
9 AppKit 0x00007fff8e95df78 -[NSValueBinder validateAndCommitValueInEditor:editingIsEnding:errorUserInterfaceHandled:] + 488
10 AppKit 0x00007fff8e99e37d -[_NSBindingAdaptor _validateAndCommitValueInEditor:editingIsEnding:errorUserInterfaceHandled:bindingAdaptor:] + 183
11 AppKit 0x00007fff8e99e45b -[_NSBindingAdaptor validateAndCommitValueInEditor:editingIsEnding:errorUserInterfaceHandled:] + 211
12 AppKit 0x00007fff8e898c0a -[NSTableView textShouldEndEditing:] + 351
13 AppKit 0x00007fff8e91ae68 -[NSTextView(NSSharing) resignFirstResponder] + 426
14 AppKit 0x00007fff8e408bf5 -[NSWindow makeFirstResponder:] + 429
15 AppKit 0x00007fff8e3b8cd6 -[NSWindow sendEvent:] + 5272
16 AppKit 0x00007fff8e35168f -[NSApplication sendEvent:] + 5593
17 AppKit 0x00007fff8e2e7682 -[NSApplication run] + 555
18 AppKit 0x00007fff8e56680c NSApplicationMain + 867
19 Departments 0x0000000100001412 main + 34
20 Departments 0x00000001000013e4 start + 52
21 ??? 0x0000000000000003 0x0 + 3
)


#2

Is your Manager NSPopUpButton’s “Selected Object” binding bound to Depts.selection.manager?

And if so, is the Depts array controller associated with the Department entity name, etc.? (in the Attributes Inspector)


#3

Yes, for both questions.

I also get this error changing departments in the Department View.

Thanks for your response

2012-01-11 12:34:37.262 Departments[3041:707] Error setting value for key path selectionIndexes of object <NSArrayController: 0x100368460>[entity: Department, number of selected objects: 1] (from bound object <NSTableView: 0x100365720>): [<Employee 0x100180370> valueForUndefinedKey:]: the entity Employee is not key value coding-compliant for the key “manager”.
2012-01-11 12:34:37.265 Departments[3041:707] (
0 CoreFoundation 0x00007fff8aef9286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff86004d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8aef90ba +[NSException raise:format:arguments:] + 106
3 AppKit 0x00007fff8d6285c5 -[NSBinder _setValue:forKeyPath:ofObject:mode:validateImmediately:raisesForNotApplicableKeys:error:] + 893
4 AppKit 0x00007fff8d627eaa -[NSBinder setValue:forBinding:error:] + 260
5 AppKit 0x00007fff8d8e9562 -[NSTableBinder tableView:didChangeToSelectedRowIndexes:] + 136
6 AppKit 0x00007fff8da06030 -[_NSBindingAdaptor tableView:didChangeToSelectedRowIndexes:] + 153
7 AppKit 0x00007fff8d4bdb71 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 139
8 AppKit 0x00007fff8d4945fa -[NSTableView _enableSelectionPostingAndPost] + 425
9 AppKit 0x00007fff8d4ba9c2 -[NSTableView mouseDown:] + 5030
10 AppKit 0x00007fff8d4200e0 -[NSWindow sendEvent:] + 6306
11 AppKit 0x00007fff8d3b868f -[NSApplication sendEvent:] + 5593
12 AppKit 0x00007fff8d34e682 -[NSApplication run] + 555
13 AppKit 0x00007fff8d5cd80c NSApplicationMain + 867
14 Departments 0x0000000100001412 main + 34
15 Departments 0x00000001000013e4 start + 52
16 ??? 0x0000000000000003 0x0 + 3


#4

Unfortunately my best advice at this point is to re-check all of your bindings. Somehow an Employee entity is being used in the context that a Department is expected.

Adam


#5

Hi Adam,

I just figured it out. It looks like at some point when doing the binding I had drilled down a little tol far when binding to the PopUp Button and had extra bindings at the cell level. I had used incorrect values there, but correct values in the actual button so I didn’t see them. I had a related and unrelated question for you.

Is there a reason that you would ever bind to the cell?

In Department.m, we use willChangeValueForKey… etc. Why do we do this?

Thanks for the great book


#6

Ah – glad you got it sorted out. One hint for debugging these binding problems in the future: you can also see all of the places bind to an object in the Connections Inspector (or panel). So in this case, looking at the Array Controller’s connections panel. Sometimes you can use this to spot places that are bound ton an object that shouldn’t be.

I don’t know of any reason to bind a cell to something. And unfortunately it’s rather easy to accidentally select cells in IB. And here I’m talking about NSCells, not view based table views’ NSTableCellViews, which we bind to.

In Departments.m we are overriding methods that NSArrayController would try to call on an object (since it is KVC-compliant). Because we’re interacting with the primitive values, we need to do the appropriate KVO-related cues, such as willChangeValueForKey:. This lets us get a little closer to the inner workings of Core Data and still allow it to behave consistently otherwise.

Adam