Re: Sorting on a table view of a managed object - debugger throws exception
Re: Sorting on a table view of a managed object - debugger throws exception
- Subject: Re: Sorting on a table view of a managed object - debugger throws exception
- From: Quincey Morris <email@hidden>
- Date: Thu, 2 Jul 2009 02:33:22 -0700
On Jul 2, 2009, at 01:10, Steve Cronin wrote:
10.5.7 - 10.5 SDK - target 10.4
I have a managed core data entity working pretty nicely.
I can display values in a tableView.... blah-blah....
Clicking on table column headers does as expected IN RELEASE
versions for both Tiger and Leopard.
However, in the debugger a click on table column header causes an
objc-exception.
If I step thru eventually I can survive and proceed
Error setting value for key path value of object <MyAppDelegate:
0x852600> (from bound object <MyArrayController: 0x3cbe30>[entity:
MyEntity, number of selected objects: 1](null)): [< MyAppDelegate
0x852600> setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key code.
I know, I know stop hitting yourself on the head with a hammer....
It just bugs me - why?
Have I done something wrong somewhere?
Is this a known bug?
I love this error message because it is clearly packed with
information, yet it is practically impossible to interpret without
some hints.
What happened is that something tried to set MyEntity's 'code'
property to nil, but the property has a scalar value type, so
setNilValueForKey: was called instead of the usual automatic object-to-
scalar transformation. You haven't implemented setNilValueForKey:, so
the default behavior is to call setValue:forUndefinedKey: instead,
which threw the exception you saw.
This is discussed a little bit in here:
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreDataUtilityTutorial/Articles/06_runClass.html#/
/apple_ref/doc/uid/TP40001800-CH234-SW1
but I can't find a better explanation, although I thought there was
one somewhere.
The answer is to implement setNilValueForKey: for managed object
subclasses that have scalar accessors, using the pattern shown in the
above tutorial.
If you actually do this, you can set a breakpoint there where it
detects this key, and you might even find out why something is trying
to set your property to nil. One reason it can happen is that when an
object is deleted or faulted out, it can have all its properties
forced to nil. But not always.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden