Reputation: 4061
I'm trying to access properties of a transformable core data object like this:
MainObject *localObject = [self.myArray objectAtIndex:indexPath.row];
TransformableObject *actualObject = localObject.transformableObject;
This works fine. I NSLog
actualObject
and get the correct key/value pairs:
actualObject:{
property = "Foo";
property2 = "Apple";
}
However, when I I try to:
NSLog (@"property:%@",actualObject.property)
I get -[__NSCFDictionary property]: unrecognized selector sent to instance
What am I doing wrong? In my Core Data Class, I have:
@interface MainObject : NSManagedObject
@property (nonatomic, retain) TransformableObjectClass *transformableObject;
EDIT: Here's how I set the object in Core Data
MainObject *event = (MainObject *)[NSEntityDescription insertNewObjectForEntityForName:@"MainObject" inManagedObjectContext:[AppDelegateMy managedObjectContext]];
[event setValuesForKeysWithDictionary:[myArrray objectAtIndex:i]];
Upvotes: 0
Views: 1027
Reputation: 14816
Neither -setValuesForKeysWithDictionary:
nor Core Data is magical enough to make this work without some more effort on your part. Right now, you're just assigning the dictionary in your JSON response to the new managed object's transformableObject
property. If you tried to save your context, my guess is that it would probably fail. If you want those dictionaries turned into actual TransformableObjectClass
instances, you need to do that yourself.
If you have a lot of this sort of thing in your app, you might want to look into RestKit, or one of the other Open Source JSON-to-object mapping libraries like ClassMapper.
Upvotes: 1