views:

239

answers:

2

Every time one of my managed objects is modified, I want to store the date it was modified (in an attribute which is already in my data model), for convenience when I'm syncing with other clients.

Is there a way to do this without A) re-writing all my setters manually or B) relying on myself to always change the modification date every single time the object is modified?

+1  A: 

You could register with the notification center to observe the NSManagedObjectContextObjectsDidChange notification.

This will tell you what objects are changed. You can check to see if your object is among them and take action accordingly.

Abizern
aye, this is what I ended up doing. thank you.
refulgentis
A: 

Just for completeness, you can also do this in -willSave if you already have a subclass of NSManagedObject.

Ben Stiglitz
only caveat there is that willSave is called every time the object is saved, so you need to do a little extra work to figure out if it was added/modified/deleted. The NSManagedObjectContext notifications do this for you and give you NSSets to iterate over.
refulgentis