Here I am sharing you piece of Code I am using for ManagedObjects(CoreData Objects) Request Operations.
Get references to objectManager & managedObjectContext;
RKObjectManager *objectManager = [(AppDelegate *)[[UIApplication sharedApplication] delegate] objectManager];
NSManagedObjectContext *managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
Initialise array to hold up operations in it
NSMutableArray *requestOperations = [NSMutableArray array];
Prepare first Operation and add it to requestOperations array, notice failure block is cancelling pending operations in queue.
// Setup Organization Operation
//
NSString *url = @"organizations/syncAll/";
NSMutableURLRequest *organizationsRequest = [objectManager requestWithObject:organizations method:RKRequestMethodPOST path:url parameters:nil];
RKObjectRequestOperation *organizationsOperation = [objectManager managedObjectRequestOperationWithRequest:organizationsRequest managedObjectContext:managedObjectContext success: ^(RKObjectRequestOperation *operation, RKMappingResult *result) {
..
[RKUtils isHandleStatusError:[result array]];
} failure: ^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
[objectManager cancelAllObjectRequestOperationsWithMethod:RKRequestMethodPOST matchingPathPattern:@"games/getNotStartedGames"];
[RKUtils handleError:error];
}];
[requestOperations addObject:organizationsOperation];
prepare second operation
// Setup Games Operation
//
url = @"games/syncAll/";
NSMutableURLRequest *gamesRequest = [objectManager requestWithObject:games method:RKRequestMethodPOST path:url parameters:nil];
RKObjectRequestOperation *gamesOperation = [objectManager managedObjectRequestOperationWithRequest:gamesRequest managedObjectContext:managedObjectContext success: ^(RKObjectRequestOperation *operation, RKMappingResult *result) {
..
[RKUtils isHandleStatusError:[result array]];
} failure: ^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
if (error.code == NSURLErrorCancelled) {
return;
}
[RKUtils handleError:error];
}];
[requestOperations addObject:gamesOperation];
prepare more operations
..
Set max concurrent operations count to 1
objectManager.operationQueue.maxConcurrentOperationCount = 1;
Enqueue all operations in queue. The queue will start executing operations one by one.
// Enqueue Request Operations
[objectManager enqueueBatchOfObjectRequestOperations:requestOperations progress: ^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
NSLog(@"totalNumberOfOperations : %d", totalNumberOfOperations);
NSLog(@"numberOfFinishedOperations : %d", numberOfFinishedOperations);
} completion: ^(NSArray *operations) {
NSLog(@"completion");
}];
Hope that gonna deliver your purpose. Cheers,