将现有数据预加载到基于Core Data的iPhone应用程序中? [英] Pre-load existing data into a Core Data-based iPhone app?

查看:190
本文介绍了将现有数据预加载到基于Core Data的iPhone应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在之前的项目中,我为2.2.x创建了一个使用SQLite的iPhone应用程序。它具有需要预先加载到构建中的现有数据(以XML形式)。所以我写了一个小工具,它使用libxml2来解析XML,然后写出一个SQLite数据库,然后直接包含在构建作为一个资源。这实在是太棒了。



我将在几个星期内为不同的客户开始一个新项目,其中大部分参数相同。我将有一些现有的数据,我需要解析和转储到应用程序将显示的文件。但是,这一次,我想使用Core Data并为3.x设备构建应用程序。但是,我没有明确和直接访问Core Data使用的基础数据库模式。 (这是Core Data的一点)



如何将现有数据预加载到基于Core Data的iPhone应用程序?我可以自动化过程(类似于我上面用SQLite做的)。

解决方案

假设你使用CoreData与SQLite支持,然后绝对。最直接的选择是让应用程序为您生成模式,然后使用空/ shell DB,运行xml-to-sql迁移工具。您只需要更新您的工具,以考虑CoreData从xcdm为您生成的结构。



或者,您可以使用您的工具编写包含在您的包中的sqlite数据库,然后在启动时的运行时,从sqlite数据库读取数据,spit它进入CoreData,并进行。这将使用您的sqlite DB作为预加载数据的容器,以及CoreData的数据存储中的所有进一步的数据交互。



这可能是一个偏好问题。 / p>

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 tool which used libxml2 to parse the XML, and then write out an SQLite database, which then was included directly in the build as a resource. This worked out great.

I will be starting a new project for a different client in a few weeks that has mostly the same parameters. I will have some existing data I will need to parse and dump into a file that the app will display. However, this time around I'd like to use Core Data and build the app for 3.x devices. However, I don't have explicit and direct access to the underlying database schema that Core Data uses. (Which is kind of the point of Core Data)

How can I pre-load existing data into a Core Data-based iPhone app? Can I automate the process (similar to what I did above with SQLite)?

解决方案

Assuming you're using CoreData with an SQLite backing, then absolutely. The most direct option would be to let the application generate the schema for you, then using that empty/shell DB, run your xml-to-sql migration tool. You would just need to update your tool to account for the structure that CoreData generates for you from the xcdm.

Alternatively, you could use your tool to write an sqlite db that is included in your bundle, then at runtime on startup, read in the data from the sqlite db, spit it into CoreData, and carry on. This would be using your sqlite DB as the container for the "preload data", and all further data interaction within CoreData's data store.

It's probably a matter of preference.

这篇关于将现有数据预加载到基于Core Data的iPhone应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆