Using Xcode 4.2, I created a new app using the tab bar template. For some reason this template does not give you the option to include Core Data, so I had to add it manually, which I did by following this tutorial:
When I run the app however, I get this error:
Cannot create an NSPersistentStoreCoordinator with a nil model
How do I make the model not nil? I have created Model.xcdatamodeld and added an entity (Cat) with attributes.
Also, I want to have the app begin with 5 cats for example, but the user will be able to create more cats. Where/How do I create the original 5 cats? It doesn’t seem logical to create them every time the app starts, but how can you create them in the first place?
You’ll need to instantiate a model before you try to create a persistent store coordinator. You can do that with one of the methods of NSManagedObjectModel, such as
+ mergedModelFromBundles:. Note that if you pass nil to that method, it’ll search the main bundle for models, which is probably what you want.To populate the store with some initial data, you have a few options. When your app starts up and you’re setting up your Core Data stack, you’ll probably look for an existing persistent store file. If you find it, you can just create the persistent store, add it to the coordinator, and proceed. If you don’t find it, one option is to create a new store and add some objects programmatically. Another options is to keep a pre-populated persistent store file in your bundle which you can copy to the app’s documents folder and then open. A third might be to read the default data from a server on the network and use that to populate a new store.