Using RestKit 0.20.3. Placing post/put/delete (create/update/delete) calls in the didChangeObject:(id) … forChangeType
method of the fetched results controller is not working out.
On a fetch of most recent entries from the database, the fetched results controller (FRC) gets an insert notification for a newly inserted retrieved record. That causes a POST that duplicates the object. The post itself causes two POSTS and five PUTS. The first POST is RestKit (RK) retrieving and ID. The second is the POST that caused the POST. The PUTS result from the updates from the two posts, each of which generates a change notification in the FRC. The main consequence of this is duplication of records that escalates in powers of two for each refresh.
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
switch (type) {
case NSFetchedResultsChangeInsert:
[self.timeEntryTableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
// call to RK enqueue a POST with the object via RKObjectManager
break;
case NSFetchedResultsChangeDelete:
[self.timeEntryTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];////
// call to RK enqueue a DELETE with the object via RKObjectManager
break;
case NSFetchedResultsChangeUpdate:
[self.timeEntryTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
// call to RK enqueue a PUT with the object via RKObjectManager
break;
…
}
}
The question is, what is the right way? I believe the answer involves the core data relationships and saving. Am working on it. Not certain where this will lead. Pointers welcome.
A current answer to RestKit - Send added/edited/deleted objects after offline storage would help me.