Prefilled version of Core Data?

后端 未结 3 1427
南笙
南笙 2020-12-16 17:41

My app involves getting a large json file via the internet, and then parsing it into Core Data.

Thats fine, but how could I get the already filled version of this Co

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 18:20

    There's a reasonable tutorial about pre-loading over at Ray Wenderlich's site.

    Generally - create a separate project, parse the JSON file into a core data database. Create your real project, copy the Object model and the database file to this new project.

    Now, at app start up, check if the database exists in the document's directory, and if it does not, copy your prefilled one from your app bundle.

    Make sure that the Persistent Store Coordinator works with the database in the documents folder and not the one in the app bundle.

    Update June 2012

    I've got a small example project on GitHub called PromNight which demonstrates using an Xcode Workspace with an iPad project and a OS X project to preload the data for Core Data. This uses an object model that is shared between the the two applications which helps to keep changes in sync when preloading.

提交回复
热议问题