How to add a custom initialiser to a Managed Object in Core Data

NSManagedObjects behave differently to NSObjects on many levels. If you’d like to add custom start-up behaviour in your NSManagedObjects, you’ll have noticed that overriding the standard init method isn’t working.

Instead, we can use the awakeFromFetch method. This is called automatically when a managed object is retrieved from the Core Data stack:

Use this to set default values or initialise methods in your NSManagedObject classes.

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!