Search code examples
iphonensdictionarynsmanagedobjectnsmutabledictionarykvc

Create an NSManagedObject with the contents of a NSMutableDictionary (may have NSCFString in place of number)


I want to create an NSManagedObject with the contents of a NSMutableDictionary and Visa Versa. KVC doesn't work properly in NSManagedObject so i cant use

[managedObject setValue:@"1" forKey:@"testKey"];

here managedObject has a property "NSNumber *testKey"

I have response from a webservice that i have to store in sqlite DB in my application, for that perpose i am using core data and so i have entity with name "Address" with attributes like city, state etc (all strings with zip code as int).

I have a class to parse the JSON response to get a dictionary but i have no idea how to make a managed object from that dictionary and save into my sqlite db.

Thanks in advance,

Yogesh


Solution

  • To answer your answer specifically: you can use [NSManagedObject setValuesForKeysWithDictionary:]

    More info: https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/Reference/Reference.html

    But you should really be using RestKit to interact with your API, since it handles all the object mapping automagically.