Reputation: 350
I have dates stored in core data as NSDate objects. When i try to retrieve them using a fetch request and -(id)valueForKey: i get an integer instead of an NSDate object.
NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];
NSManagedObject *entity = [results lastObject];
NSDate *date = [entity valueForKey:@"updated"];
When i use dot notation such as myEntity.updated i get an NSDate object correctly but not when i use a KVC method.
The reason I want to use -(id)valueForKey: is because i am running this code on every entity in core data and I don't want to define each entity explicitly. Alternativly i could code a bunch of if statements that test for isKindOfClass, but that will require a lot of code and seems kind of hackish.
Any suggestions would be much appreciated.
Upvotes: 1
Views: 249
Reputation: 539765
You must not call a managed object attribute "updated", that conflicts with the
isUpdated
method of NSManagedObject
.
Similar problems occur if you call and attribute "deleted", compare Core Data NSPredicate "deleted == NO" does not work as expected for a short analysis.
Renaming the attribute should solve your problem. Unfortunately, Xcode does not warn about that.
Upvotes: 3