Having an odd problem with Core Data...
I have a model where I set several other NSManagedObjects as part of another NSManagedObject (To One relations). It runs fine in the emulator but when I test on the device it crashes, giving me this error:
2014-08-10 03:14:13.292 Prologue[4099:60b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an entity named 'BookContents' in this model.' * First throw call stack: (0x184ad3100 0x1914b01fc 0x1847f2f84 0x1000794ec 0x10007846c 0x100068250 0x10006adf0 0x10006ae54 0x187ad10b0 0x187ad1044 0x187aba520 0x187ad0a44 0x187ad06d8 0x187acb370 0x187a9cb50 0x187a9ac40 0x184a937f4 0x184a92b50 0x184a90de8 0x1849d1dd0 0x18a671c0c 0x187b02fc4 0x100072fd4 0x100073014 0x191aa3aa0) libc++abi.dylib: terminating with uncaught exception of type NSException
BookContents is a model that has a relation to my main data model object Book. Here's the code that creates it:
func createBookModel() -> Book
{
var book:Book = createFromEntity("Book") as Book;
if (book != nil)
{
book.title = "New Book";
book.bookContents = createFromEntity("BookContents") as BookContents;
saveContext();
}
else
{
Log.error("Failed to create Book.");
}
return book;
}
func createFromEntity(entityName:String) -> NSManagedObject
{
var obj:NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName(entityName, inManagedObjectContext: moc) as NSManagedObject;
return obj;
}
I'm not sure what is wrong here but since it runs on the emu but not on the device it could be that something else is wrong (maybe with the data model file?). However the entity naming is correct anywhere and I prefixed the entity classes in the data model with the project's module name.