I have implemented awakeFromInsert
to set some default values and relationships in my core data objects. However, the method is being called twice, meaning that the to-many values I am adding are being added multiple times.
I am using parent and child managed object contexts.
What gives?
awakeFromInsert
will be called when you insert the object into its initial context. When this context is saved and the changes are pushed up to the parent context, it will be called again.
You can query the self.managedObjectContext
property to determine which case the method is being called for. Depending on your particular use case, you may want to check for the presence or absence of a parentContext
and act accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With