• 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: Changing the model behind contoller's back?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing the model behind contoller's back?


  • Subject: Re: Changing the model behind contoller's back?
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 5 Sep 2008 00:10:58 -0700

On Sep 4, 2008, at 23:20, Oleg Krupnov wrote:

You are right, but what KVC messages I should send to the model in
case of unordered sets, e.g. if I use Core Data?

According to the Core Data docs
(http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#/ /apple_ref/doc/uid/TP40002154-SW9),
I should call these dynamic accessors


- (void)addDirectReportsObject:(Employee *)value;
- (void)removeDirectReportsObject:(Employee *)value;

Is this contradicting with the KVC rules? I am confused...

For a Core Data to-many property, which is implemented as a NSMutableSet, you can use:


	[employee mutableSetValueForKey:@"directReports"]

as a KVO-compliant set proxy, and send it any messages you would normally send to a set, such as addObject: or removeObject: or removeAllObjects or whatever. (I assume you already know that something like [employee.directReports addObject: value] is *not* KVO- compliant. It'll update the relationship, but not trigger notifications to observers of the "directReports" property.)

The dynamic accessors are KVO-compliant convenience methods you can use instead. addDirectReportsObject: is functionally equivalent to [[employee mutableSetValueForKey:@"directReports"] addObject: value], and removeDirectReportsObject: is functionally equivalent to [[employee mutableSetValueForKey:@"directReports"] removeObject: value].

Possibly these dynamic accessors are a bit more efficient, or perhaps they use mutableSetValueForKey:, I don't really know, but it's generally a good idea to use the features that Core Data gives you, if you can.


_______________________________________________

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: 
 >Changing the model behind contoller's back? (From: "Oleg Krupnov" <email@hidden>)
 >Re: Changing the model behind contoller's back? (From: Rob Keniger <email@hidden>)
 >Re: Changing the model behind contoller's back? (From: "Oleg Krupnov" <email@hidden>)

  • Prev by Date: Strange Strange Bug
  • Next by Date: Re: How to observe NSTreeController in a custom view?
  • Previous by thread: Re: Changing the model behind contoller's back?
  • Next by thread: Re: Changing the model behind contoller's back?
  • Index(es):
    • Date
    • Thread