Default dataset for Core Data based iPhone application

后端 未结 2 1402
小蘑菇
小蘑菇 2021-02-01 10:35

I am writing an iPhone 3.0 application that uses Core Data to persist the model. I\'d like the application to be installed with a default dataset. When developing for iPhone <

相关标签:
2条回答
  • 2021-02-01 11:21

    Two options spring to mind:

    1. Write an importer from some reasonable data format (XML, JSON, etc.) and import that into your Core Data context on first run, then save the context to a persistent store.
    2. If your app only needs one persistent store, you can pre-populate it and deploy the persistent store with your app's resources. If you need multiple persistent stores, all pre-populated with the same default data, option 1 is probably going to be easier, but you could use NSPersistenStoreCoordinator's migratePersistentStore:toURL:options:withType:error: (or the equivalent in iPhone Core Data -- still under NDA) to create the new store from the pre-poplated store for each new store needed.

    In my experience the code to implement option 1 is nearly the same code as required to prepopulate a persistent store, so perhaps there's really only one option with two points of view.

    0 讨论(0)
  • 2021-02-01 11:21

    You can use Plist to store the initial data and populate your persistent store on first run. This approach is easier than having to write your own custom XML parser.

    0 讨论(0)
提交回复
热议问题