CoreData: error: Failed to call designated initializer on NSManagedObject class

后端 未结 5 1026
时光说笑
时光说笑 2020-12-01 10:08

I have a little damn problem with CoreData. I want to insert a new Object, so I first have to create one. This is done by that code:

Challenges *newChallenge         


        
5条回答
  •  旧巷少年郎
    2020-12-01 11:07

    In case you ask yourself "OK, so how to I get that entity?" (like I did), you do this by using the entityForName method like so:

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Challenges" inManagedObjectContext:self.managedObjectContext];
    
    Challenges *newChallenge = [[Challenge alloc] initWithEntity:entity insertIntoManagedObjectContext:self.managedObjectContext];
    

    Hope this helps, this thread has helped me a lot!

提交回复
热议问题