Re: Another Core Data Ivar Setter and Undo Issue
Re: Another Core Data Ivar Setter and Undo Issue
- Subject: Re: Another Core Data Ivar Setter and Undo Issue
- From: "Timothy J. Wood" <email@hidden>
- Date: Tue, 3 Jul 2007 19:21:14 -0700
On Jun 26, 2007, at 2:29 PM, Ian G. Gillespie wrote:
I've searched the archives and couldn't find and answer to my
question, so here goes...
I have Core Data app where one entity say, "Department", wants to
know when there is a change in one of its "Employee" entities
(typical one-to-many relationship example). In the past I
registered Department as an observer for changes in its Employees
for the key paths of interest. This worked fine accept that it led
to some performance issues when a Department was registering for
changes in say 5000-10,000 Employees. To address this I wanted to
use my know observing-notification system using
NSNotificationCenter. I started implementing custom accessors in
my Employee managed object sub-class so that I could post
notifications (as seen below).
The problem is when I undo a change made on an Employee's property
the setMyValue: method is not called again. It is only called when
the user actually changes a value via bindings on the UI. I was
hoping that when Core Data invokes undo that it would call the
appropriate setter value for the property that changed. Is this
the expected behavior of Core Data?
Any reason you aren't using KVO? The -will/-did methods in your
example will trigger a key-value observation notification on the 'do'
case and the internal undo & redo state changes will ping KVO too.
So you might be able to just delete this method and then sign up for
KVO:
[target addObserver:observer forKeyPath:@"myValue" options:mask
context:NULL];
then implement the KVO observing method on your observer:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)
object change:(NSDictionary *)change context:(void *)context;
As with notifications, you need to remember to remove the
observation.
-tim
_______________________________________________
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