views:

34

answers:

1

This question is a follow up on this question. I am using the JSON Library found at http://code.google.com/p/json-framework/.


My Core Data object model has a many-to-many relationship to itself and as such, has a set for its sub object. In JSON, the set is represented through an array of object ids. Nothing really exotic.

When I am calling setValuesForKeysWithDictionary on the managed object with the object structure I get from parsing the json string, I receive this exception:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM minusSet:]: unrecognized selector sent to instance 0x6c7b440'

If someone can explain why, I'm all ears. I also receive some exception from undefined key but this is understandable(JSON contains extra fields) and totally manageable.

Now my question is:

Am I missing something here because in the other question, the person who answered and OP didn't report any of this problem. I could patch it and handle the faulty operation by overriding setValuesForKeysWithDictionary and passing when the key is a relationship but this makes the code a lot less generic which I quite like.

A: 

I think the problem is that your JSON deserialization is creating arrays, but managed object to-many relationships are represented by sets. I.e. you need NSSet rather than NSArray. You can convert an NSArray to an NSSet by doing [NSSet setWithArray:theArray].

Daniel Dickison