我可以在一个应用程序中创建一个Core Data对象图,然后从另一个预设状态使用它吗? [英] Can I create a Core Data object graph in one application, then use it in another from a preset state?

查看:205
本文介绍了我可以在一个应用程序中创建一个Core Data对象图,然后从另一个预设状态使用它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序现在有一个.plist约5,000个字典,在运行时,我用来创建我的自定义类的5,000个对象。每一个都包含几个字符串,一些布尔值等。这是一个相当快的过程,需要几秒钟,顶部,但它有点笨重使用.plist与成千上万的对象。

My app as it stands now has a .plist of around 5,000 dictionaries which, at runtime, I use to create 5,000 objects of my custom class. Each one contains a few strings, some boolean values, etc. This is a fairly quick process, takes a few seconds, tops, but it's a bit unwieldy using a .plist with thousands of objects.

我要迁移到Core Data(我以前从未使用过),所以初始步骤是将数据从.plist导入这些自定义对象,然后将它们保存在上下文。

I'm going to migrate to Core Data (which I've never used before), so the initial step is going to be getting the data from that .plist into those custom objects, then saving them in the context. I've watched the videos and such, and think I'm going to be okay doing that.

我的第一个问题是:我可以创建对象图和数据模型在一个小的,单独的应用程序(说,称为ObjectMaker),然后保存它,并导入.sqlite或任何格式我导出我的数据到我正在做的实际应用程序?从那里,我将执行所有的抓取请求,进一步编辑和保存数据等。

My first question is: can I create the object graph and data model in a small, separate app (say, called ObjectMaker), then save it there, and import the .sqlite or whatever format I export my data as into the actual app I'm making? From there, I'd be performing all of the fetch requests, further editing and saving of the data, etc.

我的第二个问题是:可以提供对象图的第一次启动状态,用户在第一次打开我的应用程序时会获得(包含5,000个已准备好的对象并可以访问/查询等)。我想要应用程序发布与.sqlite或任何格式我导出我的数据到ObjectMaker应用程序,并使用那个排他,而不知道.plist存在。

My second question is: is it possible to provide a "first launch state" of an object graph that a user would get on first opening my app (with those 5,000 objects ready-made and ready to be accessed / queried, etc.? I'd like the app to ship with the .sqlite or whatever format I export my data to in the ObjectMaker app, and use that exclusively, without ever knowing that the .plist existed.

非常感谢任何和所有答案^ _ ^

Thanks very much for any and all answers ^_^

推荐答案

我们经常使用我们的许多应用程序。在开发过程中,我们建立了数据模型,但往往需要导入一堆主数据,并执行一些默认应用程序配置,以达到我们将运送产品的sqlite数据库的初始状态。

We do this quite often with many of our apps. During development we build out the data model but often times need to import a bunch of master data and perform some default app configuration to get to an "intial state" of the sqlite database that we would ship the product with.

在应用程式委托中,我们有一个#define(或变数),可用来切换「DB建立与汇入」模式。运行创建模式时,我们删除任何现有的.sqlite文件,重新初始化Core Data堆栈,然后运行导入例程将我们的.plist和.csv数据转换为所需的Core Data对象。

In the app delegate we have a #define (or variable) you can use to toggle " DB create & import" mode. When running the create mode we delete any existing .sqlite file, reinitialize the Core Data stack, then run the import routines to convert our .plist and .csv data into the required Core Data objects.

我们使用模拟器并构建和运行。一旦我们导入了数据和配置的应用程序的默认选项,我们导航到包含您正在执行的应用程序的模拟器文件夹,并复制数据库并将其放回项目文件。

We use the simulator and build and run. Once we have the data imported and the default options of the app configured we navigate to the simulator folder that contains the app you are executing and copy the database and drop it back into the project file.

当数据库创建&导入模式未启用时,它首先检查在适当位置是否有数据库。如果不是,它会将默认数据库从主包复制到设备上的正确位置。

When the "DB create & import" mode is not enabled it first checks to see if there is a database at the proper location. If not, it copies the default database from the main bundle into the proper location on the device.

这篇关于我可以在一个应用程序中创建一个Core Data对象图,然后从另一个预设状态使用它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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