核心应用程序中的数据信息 [英] Core Data information in application

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

问题描述

我有一个我正在构建的应用程序,它有一些内置的数据,包含在核心数据数据模型中。当我运行应用程序到模拟器,数据就在那里,一切都是peachy。
然而,当我部署应用程序到设备(iPad),该应用程序工作正常,除了没有数据。
看起来像一个没有脑子,但似乎找不到一个开关或复选框或任何东西告诉xcode部署数据与模型。



更新:



建议的重复项并不能真正帮助我。我不知道我完全明白需要做什么。我有sqllite数据库与我的初始数据集,我需要加载到核心数据每次我启动应用程序?



此外,用户编辑/添加/删除的数据怎么办?



这是否会丢失或者是否允许留在核心数据中?

解决方案<



您需要做的就是根据上面的重复问题准备一组初始数据。数据库文件将与您的应用程序捆绑在一起。该位置 - 在主束中 - 将不同于部署的位置。在我工作的项目中,我们使用应用程序文档目录作为部署位置。



因此,逻辑如下。在您的应用程序委托中,在 didFinishLaunchingWithOptions 方法中,检查应用程序文档目录中是否存在 .sqlite



从那时起,使用该文件进行所有数据库操作。

如果没有从主包中获取文件, p>

这就是如何在你的应用程序中加入一个预加载的数据库。



现在,地点?为此,您应该在项目中创建另一个目标。该目标将基于数据模型创建数据库,并用您的初始数据填充它。创建后,您应该将该文件拖放到Xcode上,以便将其包含在应用程序的资源包中。


I have an app that I'm building where it has some data built into it that is contained in a core data data model. When I run the app to the simulator, the data is there and everything is peachy. However, when I deploy the app to the device (an iPad), the app works fine, except there is no data. Seems like a no brainer, but can't seem to find a switch or check box or anything to tell xcode to deploy the data along with the model.

Update:

The suggested duplicate didn't really help me. I'm not sure I entirely understand what needs to be done. I have the sqllite db with my initial set of data, do I need to load that into core data every time I launch the app?

Also, what about data that the users edits/adds/deletes?

Does that then get lost or is that allowed to stay in core data?

解决方案

What you need to do is prepare an initial set of data as per the duplicate question above.

The database file will be bundled with your app. That location - in the main bundle - will be different to the deployed location. In projects I've worked in, we use the application documents directory to be the deployed location.

So, the logic goes as follows. In your app delegate, in the didFinishLaunchingWithOptions method, check to see if the .sqlite file exists in your application documents directory. If it doesn't get the file from your main bundle and copy it to that location.

From that point on, use that file for all your database operations.

That's how you include a preloaded database in your app.

Now, what about creating the preloaded database in the first place? For that, you should create another target in your project. That target will create the database based upon the data model, and populate it with your initial data. Once it's created, you should drag and drop that file back onto Xcode so that it's included in your app's resources bundle.

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

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