0

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

Yogesh Maheshwari
  • 1,324
  • 2
  • 16
  • 37
  • What makes you think that KVC doesn't work in Core Data? – Abizern Apr 17 '12 at 11:35
  • KVC does work but in the case that i have specified it wouldn't work. I cant pass NSNumber as value when feeding into NSString while in general there isn't any problem with that – Yogesh Maheshwari Apr 18 '12 at 14:06

1 Answers1

2

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.

Jacek Lampart
  • 1,741
  • 13
  • 25