I\'m doing an iPhone application. In this app, I just want to have a database to be used as a looked up table for values in my app. The only thing the database will do was t
Please refer to the Core Data Programming Guide, or see below (copy from the PG):
" How do I initialize a store with default data?
There are two issues here: creating the data, and ensuring the data is imported only once. There are several ways to create the data.
You can create a separate persistent store that contains the default data and include the store as an application resource. When you want to use it, you must either copy the whole store to a suitable location, or copy the objects from the defaults store to an existing store. For small datasets, you can create the managed objects directly in code.
You can create a property list—or some other file-based representation—of the data, and store it as an application resource. When you want to use it, you must open the file and parse the representation to create managed objects.
You should not use this technique on iOS, and only if absolutely necessary on Mac OS X. Parsing a file to create a store incurs unnecessary overhead. It is much better to create a Core Data store yourself offline and use it directly in your application. There are also several ways to ensure that the defaults are imported only once:
If you are using iOS or creating a non-document-based application for Mac OS X, you can add a check on application launch to determine whether a file exists at the location you specify for the application’s store. If it doesn't, you need to import the data. For an iOS-based example, see CoreDataBooks .
If you are creating a document-based application using NSPersistentDocument, you initialize the defaults in initWithType:error:.
If there is a possibility that the store (hence file) might be created but the data not imported, then you can add a metadata flag to the store. You can check the metadata (using metadataForPersistentStoreWithURL:error:) more efficiently than executing a fetch (and it does not require you to hard code any default data values).
"
As mentioned above, generally we need to create a pre-populated default store with code, then use it as a resource file, and copy it from resource bundle to document directory if the coredata file is missing. Please search the CoreDataBooks code example in your Xcode Organizer (or Apple Developer Center), and look at the - (NSPersistentStoreCoordinator *)persistentStoreCoordinator method.