Question

I am trying to understand how RestKit's fetching of objects works. As far as I understand it, when I call,

[[RKObjectManager sharedManager] getObjectsAtPath:@"/mypath/objects" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        // Use objects that are returned.
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        // Handle error
    }];

Restkit will attempt to load the objects at the specified path from the web-service and call the success block once the objects have been retrieved. It will also update the core data object graph with the mapping I provide before it calls the success block. What if I only want to the objects that are in core data? How do I access those objects? Should I use the sharedManager's managedObjectStore's mainQueueManagedObjectContext to perform NSFetchRequests directly on it and only call getObjectsAtPath:parameters:success:failure: if I want the Core Data persistent store to be updated?

Was it helpful?

Solution

As far as I understand it

Yes, basically. RestKit will go and get the data from the server at the specified path, deserialise it and map it into objects based on the mappings and response code / descriptor. If you have specified to use Core Data then it will save the results before calling the success block.

What if I only want to the objects that are in core data

Then you don't use RestKit, you just access the mainQueueManagedObjectContext, often with an NSFetchedResultsController.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top