为核心数据应用程序提供基础数据? [英] Provide Base Data for Core Data Application?

查看:22
本文介绍了为核心数据应用程序提供基础数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Core Data 应用程序(适用于 iPhone 3.0,但我认为这在这里没有什么区别),它需要附带一个充满数据的入门"数据库.使用 SQLite,我只需让应用程序在首次启动时将已填充的数据库从捆绑包复制到应用程序的文档目录中,然后加载该数据库 - 所有信息都会随之而来,我们就可以开始了.但是对于 Core Data,我不确定是否可以将 Persistent store 保存到 App bundle 并在让 Core Data 开始做它的事情之前复制它.这会导致任何问题吗?初始数据比较多,不想打包成其他格式,还得自己解析.

I'm working on a Core Data app (for iPhone 3.0, though I don't think that really makes a difference here) and it will need to ship with a "starter" database filled with data. With SQLite, I would just have the App copy the populated database from the bundle into the App's documents directory on first launch and then load that database - all the information would come along with it and we'd be ready to go. But with Core Data, I'm not really sure if I can just save the Persistent store to the App bundle and copy it before having Core Data start doing its thing. Will this cause any problems? There is quite a bit of initial data, so I don't want to package it in another format and have to parse through it.

推荐答案

是的,您可以复制预先填充的持久存储.

Yes, you can copy over a pre-populated persistent store.

我创建了一个填充商店的 Mac 应用程序.它被复制到我的包中,并在开始时复制到 Docs 目录.这工作正常.我听说 Core Data Books 示例的开发方式相同.

I created a Mac app that populates a store. It is copied into my bundle and at start, copied to the Docs directory. This works fine. I am told the Core Data Books example was developed the same way.

请注意,这并不意味着您可以复制任何旧的 SQLite 文件.它必须是一个 Core Data 持久存储,但我认为您根据您的问题理解了这一点.

Please note this doesn't mean you can just copy over any old SQLite file. It has to be a Core Data persistent store, though I think you understand that based on your question.

这篇关于为核心数据应用程序提供基础数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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