• 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
Re: setPrimitiveValue:forKey: and to-many relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >setPrimitiveValue:forKey: and to-many relationships (From: "Sean McBride" <email@hidden>)
 >Re: setPrimitiveValue:forKey: and to-many relationships (From: Quincey Morris <email@hidden>)

  • Prev by Date: sizeof(unsigned long long)
  • Next by Date: Re: sizeof(unsigned long long)
  • Previous by thread: Re: setPrimitiveValue:forKey: and to-many relationships
  • Next by thread: re: setPrimitiveValue:forKey: and to-many relationships
  • Index(es):
    • Date
    • Thread