angeleke
angeleke

Reputation: 219

EXC_BAD_ACCESS in NSEntityDescription creation of Core Data

I am learning CoreData from a book based in iOS4, so, implementing the example code from the book I am migrating the code to iOS5 (with storyboards and ARC). I have also implemented the iOS4 code and it works perfectly, but in the iOS5 version I get an EXC_BAD_ACCESS when I get the NSEntityDescription from the name of the model object:

AppDelegate *appDelegate =[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext]; 

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Customer" inManagedObjectContext:context];

The signal arises in the last line of code. I know the delegate should pass the context to the viewcontroller, but with this code I am sure the context is not the problem.

Any ideas? Why could I get an EXC_BAD_ACCESS here? Can I be sure this line is correct?

Upvotes: 1

Views: 1110

Answers (1)

Mundi
Mundi

Reputation: 80265

It seems to mean that your entity string is perhaps wrong? To avoid the crash you could use something like:

NSEntityDescription *entity = [[managedObjectModel entitiesByName] 
   objectForKey:@"Customer"];

Upvotes: 2

Related Questions