Well, now that I've convinced myself that NSManagedObjectContextObjectsDidChangeNotification does not give enough information, and that there is no way to reliably maintain a KVO observer of a managed object, I was going to bite the bullet and implement custom setters for all the properties I want to observe, slipping in the posting of a notification, like this:

- (void)setFoo:(NSWhatever*)value
{
    [self willChangeValueForKey:@"foo"];
    [self setPrimitiveFoo:value];
    [self didChangeValueForKey:@"foo"];

NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                              value, @"NewValue",
                              @"foo", @"key",
                              nil] ;
[[NSNotificationCenter defaultCenter] postNotificationName:@"ModelHit"
                                                        object:self
userInfo:userInfo] ;

}

For attributes, I believe it is guaranteed that any proper KVO- compliant change to a Foo will use this accessor and thus my notification will be posted whenever an attribute value changes.

But what about to-many relationships? Think DepartmentAndEmployees. Imagine I have a OrgChart object. My OrgChart wants to receive a notification, observation, or SOMETHING when the directReports of any Employee is changed.

How can I get this? According to the documentation, a to-many relationship is ordinarily modified by mutating the mutable set proxy. So there is no always-invoked accessor to override.

Certainly there must be a solution to this very basic problem. What is it?

Thanks,

Jerry Krinock _______________________________________________

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 arch...@mail-archive.com

Reply via email to