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

- by

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.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.