简体   繁体   English

RestKit 核心数据集成

[英]RestKit Core Data Integration

I've gone through a few days of pain using RestKit to map some JSON.我已经使用 RestKit 映射一些 JSON 经历了几天的痛苦。 Being new to Core Data I made the assumption that once RestKit had mapped the data to my RestKit created DB, ie作为 Core Data 的新手,我假设一旦 RestKit 将数据映射到我的 RestKit 创建的数据库,即

objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"EFrontCD.sqlite"];

I could leave the RestKit world.我可以离开 RestKit 世界了。 I then attempted to load my data into a UITableViewController implementing the RKManagedObjectStore protocol and doing the usual stuff, but I get the error然后我尝试将我的数据加载到实现 RKManagedObjectStore 协议并执行常规操作的 UITableViewController 中,但出现错误

UIManagedDocument can only read documents that are file packages 

2 questions: 2个问题:

  1. Do I now have to do everything via RKManagedObjectStore?我现在必须通过 RKManagedObjectStore 做所有事情吗?
  2. Can I get RestKit to use an existing Core Data package instead rather than creating a .sqlite file as above?我可以让 RestKit 使用现有的 Core Data 包而不是像上面那样创建 .sqlite 文件吗?

Thanks, Ben谢谢,本

Answering the first part of my question, this is what I was looking for:回答我问题的第一部分,这就是我要找的:

RKObjectManager *objectManager = [RKObjectManager sharedManager];
objectManager.objectStore.managedObjectContextForCurrentThread

Once you have access to the MOC RestKit has created for you, then everything appears to be the same - I can do the usual Core Data stuff.一旦您可以访问为您创建的 MOC RestKit,那么一切似乎都相同 - 我可以执行通常的 Core Data 操作。

I'm still not clear about the second question, but would certainly like to know if this is possible.我仍然不清楚第二个问题,但当然想知道这是否可能。

Seems that your missing some general understanding how Core Data works.似乎您缺少一些对 Core Data 工作原理的一般理解。 Feel free to read this tutorials to improve your knowledge about it.随意阅读本教程以提高您的知识。

Core Data always uses a data storage (this can be a SQLite, XML, ...) and when you're telling RestKit to use the SQlite as the objectStore, it will. Core Data 总是使用数据存储(这可以是 SQLite、XML 等),当你告诉 RestKit 使用 SQlite 作为 objectStore 时,它​​会。

To get the data inside you'll have to use fetch requests and link to the ManagedObjectContext which is a kind of handler between the data storage and your data.要获取内部数据,您必须使用 fetch 请求并链接到ManagedObjectContext ,这是一种数据存储和数据之间的处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM