Use NSManagedObject class without initWithEntity:?

后端 未结 2 379
深忆病人
深忆病人 2020-12-16 02:41

My problem is similar to: Problem creating NSManagedObject derived class

I have setup a NSManagedObject in Core Data and have a class for it. However, instead of cre

2条回答
  •  情深已故
    2020-12-16 03:02

    Just use initWithEntity:insertIntoManagedObjectContext: and pass a nil context, then call insertObject: in your NSMAnagedObjectContext when you are ready:

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyModelClass" inManagedObjectContext:myContext];
    id object = [[MyModelClass alloc] initWithEntity:entity insertIntoManagedObjectContext:nil];
    

提交回复
热议问题