Reputation:
I'm trying a basic test of sorting an NSManagedObject subclass. I set up a basic subclass "TestClass" with two attributes: stringField
and numberField
. They use the standard Obj-C 2.0 accessor protocol:
@interface TestClass : NSManagedObject
@property (retain) NSString *stringField;
@property (retain) NSNumber *numberField;
@end
@implementation TestClass
@dynamic stringField;
@dynamic numberField;
@end
When I try to fetch instances of this entity, I can fetch based on either attribute. However, if I use a sort descriptor, the numberField
is said to not be KVC-compliant.
Within the model, I set the numberField
to Int64, but I'm confused. I thought the wrapper (NSNumber) would handle the KVC problem. What do I need to do to make this work?
Upvotes: 0
Views: 1210
Reputation: 55164
Some initial "Is the computer on?"-type questions:
numberField
correctly when specifying the key in your sort descriptor?numberField
a transient attribute in your model?These are the common issues that I can think of that might cause such an error when fetching with a sort descriptor, the first one especially.
Also, this won't affect KVC, but your attributes' property declarations should be (copy)
rather than (retain)
since they're "value" classes that conform to the NSCopying
protocol and may have mutable subclasses. You don't want to pass a mutable string in and mutate it underneath Core Data. (Yeah, there's no NSMutableNumber or NSMutableDate in Cocoa, but that doesn't prevent creating MyMutableNumber or MyMutableDate subclasses...)
Upvotes: 2