Cannot create an NSPersistentStoreCoordinator with a nil model on new development machine

StackOverflow https://stackoverflow.com/questions/15430087

  •  24-03-2022
  •  | 
  •  

Frage

I have just set up a new machine for development using Xcode, and when I open up, build and run an existing core data project (which still works perfectly on my old machine), I receive a "Cannot create an NSPersistentStoreCoordinator with a nil model" error.

I have read through the myriad of questions on stackoverflow relating to this error, and thanks to them feel I have a better understanding of how iOS handles the database object model, and as far as I can tell, there is nothing obviously amiss.

I am using the standard initialisation method for my managed object model, namely...

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"project" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

...which is returning a nice NSManagedObjectModel on my old machine, but nil on my new one.

The bundle being compiled does contain a project.momd folder, which in turn contains a project.mom file, which is exactly the same as the compiled output on my old machine, yet one runs and one doesn't! Very frustrating!

The only thing I can think of is that there are configuration options within Xcode that I do not have set correctly on the new machine, but any help or advice would be very much appreciated!

* UPDATE *

The bundle on my new machine contains a project.mom inside of Project.momd. On my old machine, Project.mom is inside of Project.momd and I'm guessing the model name is case sensitive so I just need to decipher why xcode is compiling the mom in lower case...

Manually renaming project.mom to Project.mom inside the bundle does indeed fix the problem, albeit temporarily until the project is recompiled.

War es hilfreich?

Lösung

Open your xcdatamodeld “Folder” (using “Show Package Contents” in the Finder) to see if the xcdatamodel file(s) has the same case. In theory, the xcdatamodeld gets compiled to momd and xcdatamodel to mom.

Note that the iOS filesystem is case-sensitive while OSX’s isn’t (at least by default), so that may be why you’re getting different results on different machines.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top