Way to Prepopulate Core Data with Certain Data

后端 未结 1 1354
夕颜
夕颜 2021-01-23 14:37

Usually I populate my core data with data from internet.

But say I want to prepopulate it with data without downloading it from internet.

Say I want to store all

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 15:35

    If it's a lot of data, the fastest way is to provide a populated store. Assuming you're using a sqlite database, you can simply use the Simulator to generate it once, and then put that in your app.

    If it's a small amount of data, I'd insert the data at first start, while reading it from some form of xml, csv, or even hardcoded (script-generated) insert statements. It all depends on the situation.

    When using Core Data not read-only, you should copy the database to a place where you're allowed to write, when the app starts for the first time. In a read only situation, you can just use the database from the bundle.

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