Question

I'm updating an App which uses CoreData. On the full version I made it so the user could save his/her own data on the database (the App populates a pre-filled database).

The App was written on Xcode 4.2 and with a deployment target of iOS 4.1, so before ARC and Storyboards.

Now I want to update it a little bit, set the deployment target to 5.1 and adapt the code to the latest Xcode, so implementing Storyboards and ARC because I'm now used to it and I find it more intuitive to mantain this code. So I started a new project from scratch, I build the storyboard and I dragged most of the stuff from the 1.0 version. Additionally I've checked that the "Compile Sources" and "Copy Bundle Resources" on the Build Phases tab is ok and includes everything I've dragged.

However I'm experiencing a problem with the database. When I try to run the App it crashes telling me that:

'Cannot create an NSPersistentStoreCoordinator with a nil model'

So I'm not sure what I'm doing wrong here. I did not want to change the CoreData model, because everything remains the same, I did not add or remove any entity or attribute. So I though it would be enough to dragg the old modeld to the new project.

Any suggestion here? I could easlity write the whole codeData stuff from scratch because it's not really very complex, but I believe that the user who bougth the full version and have custom data saved, would be very upset.

Any suggestion will be REALLY welcome. Thanks in advance!

Was it helpful?

Solution

You need to check your AppDelegate method managedObjectModel. Make sure it retrieves the model (check with NSLog statements). Most likely it has to do with some naming convention:

NSString *modelPath = [[NSBundle mainBundle] 
    pathForResource:@"Model" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];

Check specifically for your modelPath.

Also, what could have happened is that when you imported the model, you did not really import all the files. The model is actually a directory called YourModel.xcdatamodeld where the final d presumably stands for "directory". In the Finder you can actually right-click and choose Show Package Contents to make sure the necessary files are there (even better to use the command line). Inside there should be a file called YourModel.xcdatamodel (without the d). In side that there should be at least a file called content (sometimes also layout). It is a simple XML file.

Make sure you imported all these into your project!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top