开发者

Adding core data to an iPhone project

I have a project in Xcode 4 that I have added coredata to, imported a *.xcdatamodel from another project, and added the library. I changed the xcdatamodel name, and pasted the necessary methods in the delegate.

But I get the error

'Cannot create an NSPersistentStoreCoordinator with a nil model'

so I need to check if my xcdatamodel file is linked with my target, but how do I do this?

This can happen when there is no xcdatamodel(d) is not present inside the .app bundle. The .xcdatamodeld file is added in the Compile Sources list (in Xcode 4, click the project on the left, select your target, go to Build Phases and check Compile Sources).

The app.xcdatamodel, is in my compile sources开发者_开发问答. Where else should I call the model to be recognized?


It seems like it can't find your object model file.

Where do you specify the location of your .mom (or .momd) file? It should look something like

NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"mom"];

What do you get if you output it to the console immediately after that (like this)

NSLog(@"%@", path);

(I predict it will be nil!)


In your app delegate, check the method managedObjectModel.

Most likely you have a wrong entity name in there somewhere.


I found an xcodeism (bug?) where I was creating a "Console" type application which had a hyphen in the name. This got translated to an underscore in some places (the data model file) and stayed as a hyphen in other places. Something about this interaction caused the above problem.

Definitely not the general case issue, but might catch a few unsuspecting corner-cases out there...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜