我有以下按升序排序的代码。
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"someproperty.name" ascending:YES];
NSMutableArray *sortedReleases = [NSMutableArray arrayWithArray:[unsortedarray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]];
[sortDescriptor release];
我想做的是做一个排序:
显示活动当前用户正在跟踪 sortedRelease 的那些(函数中的复杂逻辑??)
这是我在自定义函数中需要的:
for (Release *release in sortedReleases){
if( [[[MainController sharedMainController] activeUser] isFollowingRelease:release] ){
return NSOrderedAscending;
}
}
使用 acsending 对其余部分进行排序(目前的操作方式)
我该怎么做呢?
我知道我之前问过这个问题,也许我问错了,但这不是我想要的。我希望能够根据函数的结果进行排序。然后按字母顺序。
更新代码:
NSArray *sortedReleases = [theReleases sortedArrayUsingComparator:^(id a, id b) {
Release *left = (Release*)a;
Release *right = (Release*)b;
if(( [[[MainController sharedMainController] activeUser] isFollowingRelease:left] )&&([[[MainController sharedMainController] activeUser] isFollowingRelease:right])){
//sort alphabetically ????
}
else if (([[[MainController sharedMainController] activeUser] isFollowingRelease:left])&&(![[[MainController sharedMainController] activeUser] isFollowingRelease:right]))
{
return (NSComparisonResult)NSOrderedDescending;
}
else if ((![[[MainController sharedMainController] activeUser] isFollowingRelease:left])&&([[[MainController sharedMainController] activeUser] isFollowingRelease:right]))
{
return (NSComparisonResult)NSOrderedAscending;
}
return [left compare:right]; //getting a warning here about incompatible types
}];