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:

- (void)awakefrom {
    
    [super awakeFromFetch];
    // add custom behaviour here
}

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





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.