Created
March 31, 2013 05:44
-
-
Save amleszk/5279693 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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