I've just found out that some code that seemed to be working fine doesn't do so under all circumstances.

I have a to-many relationship (called 'elements') in a managed object ('parent'). In one spot in my code, there is a need to obtain and present all of the elements of the parent managed object, which I already have in my hand.

The parent MO is defined with an 'elements' property (nominally an NSSet). So for simply reading the set and converting it to an array, I had imagined the following would be OK:

NSArray *elements = [parent.elements allObjects];

Now, this turns out to be bad, as on occasion (and I think, when there are no elements), I get the error: *** -[NSCFArray allObjects]: unrecognized selector sent to instance <whatever>

It's interesting to see that the receiver here turns out to be an array! I'm aware that the to-many relationship is likely to be represented by a faulting proxy object, but this was unexpected.

I'm assuming this is exposing a poor assumption on my part regarding how Core Data works with to-many relationships under all conditions. What should I be doing here instead? I could presumably enumerate through the collection (no matter what flavour it currently exists in, this should work in all circumstances included the 'no elements' case).

The docs certainly contain a lot of info about accessing to-many relationships (where particular care is needed to change the set of objects in a to-many relationship correctly), but I don't recollect anything telling me that I couldn't treat the to-many relationship as a set when simply looking up which objects are there.

Cheers

-- lwe

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to