将iPhone CoreData文件从一个项目复制到另一个项目 [英] Copying iPhone CoreData files from one project to another

查看:226
本文介绍了将iPhone CoreData文件从一个项目复制到另一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建2个应用程序,一个构建持久存储,另一个使用它。



到目前为止,我已经构建了一个使用CoreData从XML文件成功构建数据库的应用程序。所以这个项目包含数据模型,实体的.h / .m文件等。



我现在试图启用第二个应用程序读取。 sqlite文件,通过将数据模型文件,与实体相关的.h / .m文件和sqlite文件复制到该项目(通过添加现有)。





在尝试复制这些文件时,是否有任何限制或正确的步骤?

解决方案

这里的解决方案看起来很简单。



只需从一个项目复制.xcdatamodel文件到另一个,然后当你在模拟器中运行你的应用程序的第一次,它会为应用程序创建一个文档文件夹。只需将保存的.sqlite或.binary文件放到设备上的yourApp / Documents目录中即可。
您可以在〜user / Library / Application Support / iPhone Simulator中找到模拟器目录。



您还可以下载,编辑和上传myApp目录,通过拖放到组织器中,从配置的iPhone。查看应用程序列表。



iPhone不支持带有核心数据的xml存储,只支持sqlite或atomic(二进制)。对于大多数应用程序来说,sqlite存储是最好的选择,因为它不是所有的都必须在运行时加载到内存中。



这是你的意思吗? p>

I'm trying create 2 apps, one that builds a persistent store, and another one that consumes it.

So far I have built one app that uses CoreData to successfully build a database from an XML file. So this project contains the data model, the .h/.m files for the entities, etc.

I'm now trying to enable the second app to read that .sqlite file by copying the data model file, the .h/.m files related to the entities and the sqlite file to that project (via add existing).

The code executes but always fails to find any objects in the database.

Are there any restrictions or correct steps to take when trying to copy over these files?

解决方案

The solution here is deceptively simple.

Just copy your .xcdatamodel file from one project to another and then when you run your app in the simulator for the first time it'll create a Documents folder for the app. Just drop your saved .sqlite or .binary files into the yourApp/Documents directory on the device. You can find the simulator directory in "~user/Library/Application Support/iPhone Simulator".

You can also download, edit, and upload the myApp directory on a provisioned iPhone by dragging and dropping into and out of the Organizer. Look at the Applications list.

The iPhone doesn't support xml stores with core data, only sqlite or atomic (binary). The sqlite store is by far the better option for most applications since it doesn't all have to be loaded into memory at runtime.

Is this what you meant?

这篇关于将iPhone CoreData文件从一个项目复制到另一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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