Shocks
Shocks

Reputation: 808

RestKit Core Data Integration

I've gone through a few days of pain using RestKit to map some JSON. Being new to Core Data I made the assumption that once RestKit had mapped the data to my RestKit created DB, i.e.

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

I could leave the RestKit world. I then attempted to load my data into a UITableViewController implementing the RKManagedObjectStore protocol and doing the usual stuff, but I get the error

UIManagedDocument can only read documents that are file packages 

2 questions:

  1. Do I now have to do everything via RKManagedObjectStore?
  2. Can I get RestKit to use an existing Core Data package instead rather than creating a .sqlite file as above?

Thanks, Ben

Upvotes: 2

Views: 1254

Answers (2)

flashfabrixx
flashfabrixx

Reputation: 1183

Seems that your missing some general understanding how Core Data works. 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.

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.

Upvotes: 0

Shocks
Shocks

Reputation: 808

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.

I'm still not clear about the second question, but would certainly like to know if this is possible.

Upvotes: 2

Related Questions