使用默认数据初始化核心数据 [英] Initialize Core Data With Default Data

查看:203
本文介绍了使用默认数据初始化核心数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于使用数据填充Core Data的基本问题。我正在建立一个应用程序,将在地图上显示ATMs。我想运送带有预加载数据库的应用程序,但给用户选择在启动应用程序时接收更新。我正在考虑使用属性列表进行更新。基本上发送所有的ATM的plist,解析plist和填充sqlite。我将在属性列表文件中有大约7000个条目,每个条目包含具有短字符串值的5-6个键。但是根据苹果iOS开发者库:

I have a basic question regarding populating Core Data with data. I am building an application, which will show ATMs on a map. I would like to ship the application with a preloaded database, but to give users the option to receive updates when they launch the app. I am thinking about using a property list for the update. Basically send a plist of all the ATMs, parse that plist and populate the sqlite. I will have around 7000 entries in the property list file, each entry containing 5-6 keys with short string values. But according to the Apple iOS Developer Library:


您可以创建一个属性列表或一些其他基于文件的
表示,的数据,并将其存储为应用程序资源。
当您想要使用它时,您必须打开该文件并解析
表示以创建受管对象。你不应该在iOS上使用这种
技术,只有在Mac OS X上绝对必要时。
解析文件以创建商店会产生不必要的开销。
更好地离线创建一个核心数据存储,并直接在应用程序中使用

You can create a property list—or some other file-based representation—of the data, and store it as an application resource. When you want to use it, you must open the file and parse the representation to create managed objects. You should not use this technique on iOS, and only if absolutely necessary on Mac OS X. Parsing a file to create a store incurs unnecessary overhead. It is much better to create a Core Data store yourself offline and use it directly in your application.

我应该还是发送一个属性列表或者想一个替代解决方案来更新应用程序的数据库?

Should I still be sending a property list or rather think for an alternative solution to update the application's database?

PS我正在考虑使用Rails应用程序来提供更新 - 基本上是发送plist文件。

P.S. I am thinking about using a Rails app for providing updates - basically sending a plist file.

推荐答案

几个月前,做了相当多的搜索找到一个很好的简单的答案,没有找到它,最终定居在一个滚动自己的解决方案,花了一些时间比我希望,但至少非常有帮助在学习理解核心数据。

I had nearly the same question a few months back, did quite a bit of searching to find a nice easy answer, failed to find it and eventually settled on a roll-your-own solution that took a bit more time than I would have hoped, but was at least very helpful in learning to understand Core Data.

基本上,解决方案是写一个解析我的源数据的实用程序(对我来说是一个逗号分隔的文本文件,使用相当方便的'cCSVParse'库 - http://michael.stapelberg.de/cCSVParse )并将其插入到Core Data Managed Objects中,然后保存为一个sqlite持久存储。

Basically the solution was to write a little utility that parsed my source data (which for me is a comma-separated text file, parsed using the quite handy 'cCSVParse' library - http://michael.stapelberg.de/cCSVParse ) and inserted it into Core Data Managed Objects and then saved that off as a sqlite persistent store. Then the sqlite store(s) can be shipped with the app, and uploaded by the user when they buy more data.

您可以从plist(或任何其他语言)编写一个转换, )转换为应用程序本身中的核心数据表示,但如果数据只是以某种核心数据形式在其余时间生效,那么为什么不让您的强大开发框在将数据发送给用户之前,而不是将数据发送到手机,并使它做的工作?

You could write a conversion from plist (or whatever) into the core data representation within the app itself, but if the data is just going live out the rest of its days in some core data form, why not let your beefy dev box do the heavy lifting before you send the data to the user, instead of shipping the data to the phone and making it do the work?

这篇关于使用默认数据初始化核心数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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