Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

iphone - Prefilled version of Core Data?

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 Core Data database into my app, so it is there when they first launch it. And the user can decide to refresh it later.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...