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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to