开发者

Pre loaded database on iPhone?

开发者 https://www.devze.com 2023-01-02 08:46 出处:网络
I developing an app that is read-only. The data has relationships, so I cannot just use a plist or something similar.

I developing an app that is read-only. The data has relationships, so I cannot just use a plist or something similar.

Questions:

  • Should I use Core Data for such a requirement?
  • If so, how would I enter the data and then release the app with that data?
  • How would I make it so that the app doesn't need to re-populate a DB every time it loads?
  • Is there a 开发者_开发百科way to create a Core Data model using sql commands with sqlite (i.e. insert into, etc)?


You may use an SQLite database to accomplish this.

  1. Create the model in your iOS app.
  2. Create and populate the database in a Mac OSX utility command-line app
  3. Copy the sqlite file into your iOS app and link it with some code

Work through these two tutorials, line by line, and afterward you will have a good enough understanding (and code sample) to complete this task in your own app.

  • Core Data on iOS 5 Tutorial: Getting Started
  • Core Data on iOS 5 Tutorial: How To Preload and Import Existing Data


In my short experience with the iPhone, you have two options.

  1. Write a data import function and run it on the first application launch.
  2. Use solution 1, but build the initial sqllite file in the simulator, and then on first application launch, copy it into the app's documents directory.

From past experience, option 2 is much quicker for user experience, and the preferred solution.


You can write a utility project that imports the app's data model and use throwaway code n that project to populate the Core Data DB. Once the DB is populated, simply copy the actual file to the app project's resources folder and then when you set up your persistent store, use NSBundle to return the path to the DB file within the built app.

And you're done.

0

精彩评论

暂无评论...
验证码 换一张
取 消