这是我用来对 NSMutableArray 中的项目进行排序的代码。代码可以正常工作,但应用过滤器后,顺序不会改变。难道我做错了什么?
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;
}];