I should of known it would be the relationships causing trouble.

Converting the JSON messages back into managed objects should be quite simple.  You loop around your dictionary converting stuff back.  A useful shortcut is provided by the managed object function setValuesForKeysWithDictionary.  Given that the dictionary came from a managed object in the first place we know that all of our keys should be in our object so:

2010-10-28 12:07:26.404 Cooking Companion[29814:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary managedObjectContext]: unrecognized selector sent to instance 0x8250370'

Or not. So we assume that the instance in question is inside my NSDictionary but we can’t tell which one as po will print the contents but not the addresses of the objects. We could override the NSDictionary description function to print them out but we only need to do this for debugging and there aren’t that many:

(gdb) print (id)[structureDictionary objectForKey:@"author"]
$1 = (id) 0x2a8dd68
(gdb) print (id)[structureDictionary objectForKey:@"category"]
$2 = (id) 0x841bf00
(gdb) print (id)[structureDictionary objectForKey:@"cookingtemp"]
$3 = (id) 0x8412f10
(gdb) print (id)[structureDictionary objectForKey:@"cookingtempunits"]
$4 = (id) 0x2a8dd68
(gdb) print (id)[structureDictionary objectForKey:@"cookingtime"]
$5 = (id) 0x841fe50
(gdb) print (id)[structureDictionary objectForKey:@"desc"]
$6 = (id) 0x841cbe0
(gdb) print (id)[structureDictionary objectForKey:@"gead"]
$7 = (id) 0x0
(gdb) print (id)[structureDictionary objectForKey:@"head"]
$8 = (id) 0x0
(gdb) print (id)[structureDictionary objectForKey:@"heat"]
$9 = (id) 0x841fde0
(gdb) print (id)[structureDictionary objectForKey:@"ingredients"]
$10 = (id) 0x841fa60
(gdb) print (id)[structureDictionary objectForKey:@"method"]
$11 = (id) 0x2a8dd68
(gdb) print (id)[structureDictionary objectForKey:@"photo"]
$12 = (id) 0x2a8dd68
(gdb) print (id)[structureDictionary objectForKey:@"preparationtime"]
$13 = (id) 0x841cb40
(gdb) print (id)[structureDictionary objectForKey:@"steps"]
$14 = (id) 0x841e750
(gdb) print (id)[structureDictionary objectForKey:@"style"]
$15 = (id) 0x2a8dd68
(gdb) print (id)[structureDictionary objectForKey:@"title"]
$16 = (id) 0x841f570
(gdb) print (id)[structureDictionary objectForKey:@"utensils"]
$17 = (id) 0x2a8dd68
(gdb) print structureDictionary
$18 = (NSMutableDictionary *) 0x841fd40
(gdb) print managedObject
$19 = (NSManagedObject *) 0x8421b50
(gdb) print moc
$20 = (NSManagedObjectContext *) 0x8502340
(gdb) n
2010-10-28 13:43:37.908 Cooking Companion[30053:207] -[__NSCFDictionary managedObjectContext]: unrecognized selector sent to instance 0x841bf00

Unsurprisingly it’s Category. Which is the first relationship it would have come to I suppose. Should’ve guessed it would be relationships causing trouble! 😛 So it looks like we should convert things depth first then assign.

This entry was posted in Programming and tagged , , . Bookmark the permalink.