Skip to content

Instantly share code, notes, and snippets.

@sstadelman
Created September 4, 2014 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstadelman/a1d34a62dfcb6b8b9f8c to your computer and use it in GitHub Desktop.
Save sstadelman/a1d34a62dfcb6b8b9f8c to your computer and use it in GitHub Desktop.
Example of deleteEntity:withCompletion
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
id<SODataEntity> entity = self.sortedEntities[indexPath.row];
NSMutableArray *arr = [NSMutableArray arrayWithArray:self.sortedEntities];
[arr removeObjectAtIndex:indexPath.row];
self.sortedEntities = arr;
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
[[DataController shared] deleteEntity:entity withCompletion:^(BOOL success) {
[[DataController shared]fetchTravelAgencyEntitySet];
/* Here, the developer knows the type of the SODataEntity, and the current ViewController.
It is possible that the end user has navigated away from this ViewController, but it is
still in the stack. So, by invoking the -fetchTravelAgencySet, the developer knows that
the model will be updated soon, and any views which are observing the result of that GET
on the model will have the fresh data. Otherwise, the other views would need to handle
the sequence of their refresh independently, and might not have the freshest information. */
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment