• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Core Data: right way to gather all elements of a to-many relationship?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data: right way to gather all elements of a to-many relationship?


  • Subject: Core Data: right way to gather all elements of a to-many relationship?
  • From: Luke Evans <email@hidden>
  • Date: Wed, 11 Feb 2009 11:48:01 -0800

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Core Data: right way to gather all elements of a to-many relationship?
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Paste with no Edit Menu
  • Next by Date: Re: Core Data: right way to gather all elements of a to-many relationship?
  • Previous by thread: Re: Paste with no Edit Menu
  • Next by thread: Re: Core Data: right way to gather all elements of a to-many relationship?
  • Index(es):
    • Date
    • Thread