Get modification date for NSManagedObject in Core Data?

Jason picture Jason · Apr 28, 2011 · Viewed 8.1k times · Source

Outside of adding an NSDate property to each Entity in my Core Data store, is there a programmatic way to get the modification date for any object?

Answer

Kendall Helmstetter Gelner picture Kendall Helmstetter Gelner · Apr 28, 2011

No, you must add a date and manage it yourself. You can use override -willSave in your managed object to update the time stamp, but read the API documentation for NSManagedObject on -willSave for how to update without causing a willSave loop (the docs even talk about the case of updating a timestamp). The docs also mention using the NSManagedObjectContextWillSaveNotification, but that may be more trouble to set up than a simple check to not set the timestamp too quickly.