Knowing when due dates are changed

Tags ( )

In planning a GTD plugin, I would like it to handle smart scheduling of due items and recurring items. In order to have it update automatically when the user changes/adds a due date or lead time, how can I monitor when those columns are changed? I assume that since I wouldn't need to affect the user's action of editing the column I don't need to make it a delegate method. Instead I should just be able to register to receive Notifications of the edit. Do columns updates post notifications like willBeEdited or didChange? Any hints as to what my plugin would need to observe to run a checkForDue method in response to such an edit?

Thanks,
Jeff

I think you'll need to

I think you'll need to register for NSManagedObjectContextObjectsDidChangeNotification notifications. You'll then need to iterate through the changed objects looking for EntryDatas. And then ask each EntryData for it's changedValues and see if @"dueDate" is in there. I think that should do it.

So just to clarify: I still

So just to clarify:

I still register with NSNotificationCenter? there's no new NSNotificationCenterForManagedObjects or anything like that with Core Data?

addOberserver: myGTDController
selector: theMessageIWantToReceive
name: NSManagedObjectContextObjectsDidChangeNotification
object: entryData

so if I register the object parameter as entryData, I shouldn't have to iterate over all changed objects, since I should only get notifications when that object type is changed, correct?

Thanks
Jeff

Only the managedObject

Only the managedObject context fires NSManagedObjectContextObjectsDidChangeNotification notifications. So you must register with the context and get all notifications, or use some other method. If you know which entryDatas you care about ahead of time you can just use KVO (key value observing). Something like:

[entryData addObserver:self forKeyPath:@"dueData" options:0 context:nil];

and balance that will a call to remove observer when you are done.

[entryData removeObserver:self forKeyPath:@"dueDate"];

and listen for changes in this method:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

Google "Introduction to Key-Value Observing Programming Guide" for the official docs on this.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.