Skip to content

Instantly share code, notes, and snippets.

@amleszk
Created March 31, 2013 05:44
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 amleszk/5279693 to your computer and use it in GitHub Desktop.
Save amleszk/5279693 to your computer and use it in GitHub Desktop.
int toIndex=0;
[self.tableView beginUpdates];
for (NSDictionary* reddit in sortedReddits) {
NSString *displayName = [reddit valueForKeyPath:@"data.display_name"];
NSUInteger fromIndex =
[_reddits indexOfObjectPassingTest:^BOOL(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
if ([[obj valueForKeyPath:@"data.display_name"] isEqualToString:displayName] ) {
*stop = YES;
return YES;
}
return NO;
}];
NSAssert(fromIndex != NSNotFound, @"");
if (fromIndex != toIndex) {
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:fromIndex inSection:0]
toIndexPath:[NSIndexPath indexPathForRow:toIndex inSection:0]];
}
toIndex++;
}
_reddits = [sortedReddits mutableCopy];
[self.tableView endUpdates];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment