I am working with CoreData
and am just implementing creationDate
and lastEditDate
properties for all my entities.
Are there default implementations for this by CoreData
that would save this work? I can't find anything on this. Thanks for your help!
CodePudding user response:
You can use awakeFromInsert
and willSave
. By extending your entity
extension YourEntity{
public override func awakeFromInsert() {
if creationDate == nil{
self.creationDate = Date()
}
super.awakeFromInsert()
}
public override func willSave() {
self.lastEditDate = Date()
super.willSave()
}
}