Re: Core Data: right way to gather all elements of a to-many relationship?
Re: Core Data: right way to gather all elements of a to-many relationship?
- Subject: Re: Core Data: right way to gather all elements of a to-many relationship?
- From: Luke Evans <email@hidden>
- Date: Wed, 11 Feb 2009 14:09:52 -0800
The documentation (Core Data Programming Guide --> Managed Object
Accessor Methods --> Custom To-Many Relationship Accessor Methods)
spells out all the stipulations for custom to-many accessors and the
code example is:
@property NSSet *employees;
... without the readonly flag. I would not expect this to hand back
an array versus a set, but I would also not specify a to-many
relationship as a read-only property.
Yes, and it seems that it's OK to set an _entire_ set for a to-many
relationship using the simple pattern:
parent.elements = <some NSSet>
according to p.62 of the Core Data Programming Guide.
However, if one wants to discourage this (and I do), then it seems
like the right thing is to set the property as read-only (after all
the docs say that the
property is only a wrapper "to suppress compiler warnings", around the
dynamic KVC handling in NSManagedObject itself).
The "dynamically generated accessor methods" (things like -
addElementsObject and -removeElementsObject) are described on p.44 of
the Guide
(which in turn references documentation for mutableSetValueForKey:).
Anyway, like you, I can't see how having a read-only flag on the
wrapping property in my NSManagedObject subclass is going to affect
how a to-many relationship is internally represented within
NSManagedObject. Moreover, I reset the declaration of the property to
the unquestionably
canonical "@property(retain) NSSet *elements" and the problem still
manifests. The "retain" appears to be required for use with GC as the
default is "assign"
which will cause warnings.
-- 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