Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URLForResource alway returns nil

I created a project without checking "use CoreData". The Project name is "glossary"

Now I changed my mind and so for I added an data model usinng Add->New File->Resource->Data Model->gave it the name Glossary->didn`t select any class->Finish.

The next step was to design my Data Model. Then I added the needed Code to my AppDelegate. For all Steps i was following this Tutorial: https://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40008305-CH1-SW1

My problem now is located in this line:

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"glossary" withExtension:@"momd"]

modelURL is always nill Creating an extra NSBundle Ref and calling mainBundle shows me that this is working, however i don`t know if it is really the right path.

Doing the same Steps on an project with selected "use CoreData" while creating works great.

Has anybody an idea?

like image 668
Jonas Avatar asked Mar 04 '11 19:03

Jonas


1 Answers

It has to do with model versioning. You want to add a versioned model (item in Xcode project tree will have .xcdatamodeld extension) and then your code will run smoothly.

In Xcode 4 when you add a new Core Data file it is versioned by default. Even if you added Core Data support after project creation.

If you don't plan to have model versions, just use .mom in your code.

like image 53
djromero Avatar answered Oct 17 '22 18:10

djromero