Here is the code I use to sort items in an NSMutableArray. The code works without errors but after applying the filter, the order doesn't change. Am I doing something wrong?
NSArray *filtered = [posts sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
Post *post1 = (Post *)obj1;
Post *post2 = (Post *)obj2;
int p1 = post1.firstPhotoVoters.count + post1.firstPhotoVoters.count;
int p2 = post2.firstPhotoVoters.count + post2.firstPhotoVoters.count;
if (p1 < p2) return (NSComparisonResult)NSOrderedAscending;
if (p1 > p2) return (NSComparisonResult)NSOrderedDescending;
return (NSComparisonResult)NSOrderedSame;
}];
postsorfiltered?NSComparisonResultcasts are completely unneccessary. Also, yourp1andp2variables are strange, since they are taking only the double of the count (and they should beNSUInteger). Sorting by double value is equivalent to sorting just by value.filteredorposts? Is theNSOrderedSamereturn always reached when the block is executed?firstPhotoVotersarenilor empty, the order won't change.