1

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?

Eimantas
  • 48,927
  • 17
  • 132
  • 168
angeleke
  • 219
  • 2
  • 10

1 Answers1

2

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"];
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • As I said, I am learning Core Data, so I didn't know this method. Using the entitiesByName method you said I've realised no entity was in the model. So the problem was I had changed the name of the .xcdatamodeld file. Although I had changed it in the delegate too, it seems that if you want to change the model file name (and you want the app works XD), you must create a new model file with this new name, as it is said here: http://stackoverflow.com/questions/5621178/rename-xcdatamodel-file Now the problem is finally solved! Thank you so much @Mundi – angeleke Feb 07 '12 at 15:50