将数据加载到核心数据模式中 [英] Load data into core-data schema

查看:93
本文介绍了将数据加载到核心数据模式中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施一个基于导航的应用程序。用户将向下钻取到所关注的节点。我使用Core Data,主要是因为我想尝试一下。如何最初加载数据库?我应该编写最初加载数据库的自定义代码,还是有一些工具可以帮我做呢?

I am implementing a navigation-based application. The user will drill down to the node of interest. I am using Core Data, mostly because I want to try it out. How do I load the database initially? Should I write custom code that loads the database initially, or is there some tool to do it for me ?

推荐答案

自动(即内置)方法,用于将数据导入到Core Data上下文中。

There is no automatic (i.e. built-in) method for importing data into a Core Data context.

我怀疑这是因为Core Data实际上是一个对象图管理框架(刚刚能够将对象图持久化到磁盘)和数据之间的映射而对象实例依赖于模式(因此至少需要一些代码)。

I suspect that this is because Core Data is really an object graph management framework (that just happens to be able to persist that object graph to disk) and the mapping between data and object instances depends on the schema (and so will require at least some code).

如果您已有其他格式的数据,则应阅读将数据导入Core Data上下文。如果你还没有其他格式的数据,你将不得不写代码(生成中间格式或直接填充上下文)。

If you already have the data in another format, you should read the section of the Core Data Programming Guide on importing data into a Core Data context. If you don't already have the data in an other format, you will have to write code either way (to generate an intermediate format or to populate the context directly).

最后,虽然它并不是一个公开的API,但是Core Data XML格式很容易手动或使用任何数量的基于XML的工具。根据数据的复杂性,您可以对XML模式进行反向工程,以生成支持XML的持久性存储。然后,您可以将此存储迁移到SQLite持久存储,您就在路上。

Finally, although it is not really a public API, the Core Data XML format is pretty easy to work with by hand or using any number of XML-based tools. Depending on the complexity of your data, you may be able to reverse-engineer the XML schema enough to generate an XML-backed persistent store. You could then migrate this store to an SQLite persistent store and you're on your way.

这篇关于将数据加载到核心数据模式中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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