1

I have a project and I want to add the Core Data handling. I have read a lot of documents and questions on the internet and on this site, but I have an error and I can't fix it.

Basically, I use for the implementation this site: http://www.theappcodeblog.com/2011/08/08/add-core-data-to-an-existing-project-in-xcode-4/ and I created a new project with core data supporting in xcode for helping me in my project. But I cant copy my project code to the core data supported xcode project.

So I have the coredata framework included, and imported in the pch file. AppDelegate.m and .h files are has the core data functions and properties.

I created a xcdatamodeld with name "User.xcdatamodeld" and with the class file which name User.h and User.m

When I try to start my application I got this error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'

The error come from the managedObjectModel getter method line, where the managedObjectModel is null.

I have tried to some another thing, for example, replace the line:

managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

to:

managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];

but with this line I got this error:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

With the first line, I debugged the modelURL and the debug line ends is: /diary.app/User.momd/

The User.momd dir is exist and has a User.mom file.

My question is same like that: Cannot create an NSPersistentStoreCoordinator with a nil model But the momd to mom replacing not works for me.

So what I doing wrong?

Many thanks!

EDIT

I found the solution (my weekend day was gone...):

start a new project with core data, and full copy the appdelegate functions and properties. Only this works for me!

Community
  • 1
  • 1
mudlee
  • 680
  • 12
  • 22

0 Answers0