The willSave documentation contains a reference to using the method for time stamping, and despite the mention of some complications associated with changing property values ββand recursion, it does not specifically warn about this use. Therefore, I think, based on this fact, this can be considered a reasonable place for applying this function.
However, the documentation refers to using NSManagedObjectContextWillSaveNotification to calculate the common timestamp, so this may be an alternative place for this to work. To search for objects that require time stamping, you need to manually check the insertedObjects and updatedObjects for managedObjectContext , but based on some quick tests, it seems to be called before the validation steps, so you will be able to set the required property here.
If you decide to stick to willSave , then you probably have 3 options.
- Required property with a default value in your model.
- A required property with a set of properties on awakeFromInsert or another suitable point.
- Additional property.
I think that any of the options is a reasonable choice, but I think that if it were me, I would choose NSManagedObjectContextWillSaveNotification only because of the complications of setting property values ββto willSave.
source share