I have an NSMutableArray that contains NSIndexPath objects, and I’d like to sort them by their row, in ascending order.
What’s the shortest/simplest way to do it?
This is what I’ve tried:
[self.selectedIndexPaths sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSIndexPath *indexPath1 = obj1;
NSIndexPath *indexPath2 = obj2;
return [@(indexPath1.section) compare:@(indexPath2.section)];
}];
You said that you would like to sort by
row, yet you comparesection. Additionally,sectionisNSInteger, so you cannot call methods on it.Modify your code as follows to sort on the
row: