如何使用预填充的Core Data数据库发送我的应用程序? [英] How can I ship my app with a pre-populated Core Data database?

查看:104
本文介绍了如何使用预填充的Core Data数据库发送我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程式使用Core Data,我想要一些内定的项目。

My app uses Core Data and I want some default entries to be inside. What's best practices of how to do that?

推荐答案

如果您已经通过以下方式加载预加载数据:一个用于在当前代码中测试的临时例程,没有理由不能使用它在模拟器目录中创建的sqlite文件(无需编写单独的Mac应用程序)。

If you're already loading the pre-load data via a temporary routine for testing in your current code there's no reason you can't use the sqlite file it creates in the simulator's directory (no need to write a separate Mac app).

如果您尚未填写该数据库,您仍然可以编写一个iOS应用程序。您可能已经编写了向商店添加数据的方法,以便您也可以使用它们导入预加载数据。

If you're not already filling that db you can still write an iOS app that does it. Odds are you've already written the methods for adding data to your store so you can use them to import the pre-load data as well.

无论如何,从模拟器的目录中获取sqlite文件并将其添加到应用程序的包中;首次启动时,您需要将其复制到应用程序目录中的相应位置,然后再将Core Data指向它。如果它真的很大,缺点是在捆绑和另一个磁盘上会有一个副本,但除了通过网络抓取数据之外,你可以做的不多。

Either way you'd grab the sqlite file from the simulator's directory and add it to your app's bundle; on first launch you'll copy it into the appropriate place in the app's directory before pointing Core Data to it. If it's really large the downside is that there will be a copy in the bundle and another on disk, but there's not much you can do about that other than grabbing the data over the network.

正如其他人建议的,如果数据量很小,您可以在首次启动时导入,使用已经为添加数据作为正常应用程序工作流程一部分的方法。

As others have suggested, if the amount of data is small you can just import it at first launch, using the methods you've already written for adding data as part of the normal app's workflow.

这篇关于如何使用预填充的Core Data数据库发送我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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