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

Bene picture Bene · Feb 3, 2013 · Viewed 40.6k times · Source

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 = [[Challenges alloc] init];
[newChallenge setName:@"TestChallenge"];
[newChallenge setRounds:[[NSNumber alloc] initWithInt:12]];
[newChallenge setShots:[[NSNumber alloc] initWithInt:5]];
[newChallenge setDate:[NSDate date]];

But however after the alloc init I get this error:

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

What the hack is going wrong?

Answer

Leo Chapiro picture Leo Chapiro · Feb 3, 2013

I think the problem is that Challenges is a NSManagedObject class and you need the designated initializer:

initWithEntity:insertIntoManagedObjectContext:

instead of

Challenges *newChallenge = [[Challenges alloc] init];

Read More..