Re: setPrimitiveValue:forKey: and to-many relationships
Re: setPrimitiveValue:forKey: and to-many relationships
- Subject: Re: setPrimitiveValue:forKey: and to-many relationships
- From: Chris Hanson <email@hidden>
- Date: Sat, 27 Sep 2008 14:58:57 -0700
On Sep 24, 2008, at 3:56 PM, Quincey Morris wrote:
IAC, it's not clear why you need to use setPrimitiveValue: at all.
Why not something like:
- (void)setChildren:(NSSet*)value_
{
[[self mutableSetValueForKey:@"children"] removeAllObjects];
[[self mutableSetValueForKey:@"children"] unionSet: value_];
}
In addition to what Ben has said, the above code is incorrect and
should not be used. It's not just incorrect as a Core Data accessor/
mutator method -- it doesn't post KVO will/did notifications around
the property mutation -- but it's also incorrect from a general Cocoa/
KVC perspective.
The reason is that it's using -mutableSetValueForKey: in the
implementation of one of the mutators that -mutableSetValueForKey: may
call, giving the potential for infinite recursion. In other words,
sending -setChildren:, which as part of -unionSet: could potentially
send -setChildren:, which as part of -unionSet:...
The -mutable{Array,Set}ValueForKey{Path}: methods are covers for your
properties, not implementation helpers for your properties.
-- Chris
_______________________________________________
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