Pre-load existing data into a Core Data-based iPhone app?

前端 未结 4 1175
Happy的楠姐
Happy的楠姐 2021-01-01 00:30

In a previous project, I built an iPhone app for 2.2.x that used SQLite. It had existing data (in XML form) that needed to be pre-loaded into the build. So I wrote a small t

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 01:21

    I don't believe Core Data provides this type of functionality inherently. If I was in your shoes, I'd write a small tool that did the XML parsing and did whatever it needed to create the Core Data model from that data and persist it. Then, just move the sqlite database Core Data generates to your real project.

    Then perhaps write some code that copies that default database into the proper location on the iPhone if a database doesn't already exist there. That will also allow you to easily revert to the "clean" data if you get yourself into a bad state since you can just delete the database file and re-run the app.

提交回复
热议问题