Re: Observing Managed Object Changes. Was: Strange ... behavior
Re: Observing Managed Object Changes. Was: Strange ... behavior
- Subject: Re: Observing Managed Object Changes. Was: Strange ... behavior
- From: Jerry Krinock <email@hidden>
- Date: Wed, 25 Feb 2009 14:16:11 -0800
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 (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