awakeFromInsert called twice with nested contexts

后端 未结 3 719
不思量自难忘°
不思量自难忘° 2021-01-24 07:39

This project uses Mogenerator and Magical Record. I have tracked down a bug to the fact that awakeFromInsert is getting called twice. Once for each of my contexts I

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 08:11

    Ok well this feels very hacky but appears to work. I created the following class methods on my human readable NSManagedObject class:

    + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
    
        JWBoard *newobject = [super insertInManagedObjectContext:moc_];
        [JWBoard awakeFromCreate:newobject];
        return newobject;
    }
    
    + (void)awakeFromCreate:(JWBoard *)board
    {
        // do setup stuff & add observers
    }
    

    Open to much better solutions!

提交回复
热议问题