I have a few NSManagedObject classes. I am pulling down some JSON data from a server which I parse into an NSDictionary object. When the conversion from JSON to NSDictionary occurs, all of my data is cast as NSStrings. When I then map this dictionary to my managedObject I get this:
Unacceptable type of value for attribute: property = "idexpert"; desired type = NSNumber; given type = __NSCFString; value = 1.'
So my managedobject is looking for an NSNumber but it’s getting a string and throwing an exception
Is there a way that when I call setValuesForKeysWithDictionary I can automagically cast the values properly for the managedobject they are going into?
Thanks!
If the json you are receiving actually has number values and they are getting cast as string you should get a new json parser. I recommend NXJson. Otherwise there wont be any magical casting happening.
If the json is returning strings such as {“idexpert”:”1″} then you can override setValuesForKeysWithDictionary and do something like the code below;