Using RestKit with Core Data I'm providing offline support when the user adds, edits or deletes objects without an internet connection by flagging the objects and saving them with Core Data.
If the internet is available again, I'll fetch all added/edited/deleted objects, save them in arrays and right know use the normal methods and loop for each item to put them on the server.
List of arrays
- fetchedAddedCompanies
- fetchedEditedCompanies
- fetchedAddedContacts
- fetchedEditedContacts
- fetchedDeletedContacts
Init method (Example for edited companies)
// Added Companies
...
// Edited Companies
for (Company *tempObj in fetchedAddedCompanies)
{
// Find keys for selected languages
[self updateAccountToServer:tempObj:addCompanyContext];
}
// ...
At the end of updateAccountToServer I post the object (self.company) with it's mapping to the server.
...
[objectManager postObject:self.company mapResponseWith:[companyMapper inverseMapping] delegate:self];
...
Question
I'm searching for a more efficient solution when the user did update a few objects and - that the special one - did add a few new objects because in contrast to all editing/deleting methods the server returns an ID for each new created object that will be stored.
1) Avoid using e.g. updateAccountToServer for each edited object and send an array of objects instead
2) Using the RKRequestQueue together with the RKObjectManager (regarding this question and a good answer)
In my opinion 1) will be hard to implement because the resourcePath for each request contains a unique ID, so I've tried 2) but missing the possibility to bind the mapping for each request using
[syncQueue addRequest:[[RKObjectManager sharedManager] objectLoaderWithResourcePath:tempString delegate:self]];
Thanks for your ideas!