【发布时间】:2015-05-15 07:55:41
【问题描述】:
如果我尝试按 playerScore 属性对 BL_Player 进行排序:
NSArray *sortedPlayers = [players sortedArrayUsingComparator: ^(BL_Player *a1, BL_Player *a2) {
return [a1.playerScore compare:a2.playerScore options:NSNumericSearch];
或
NSArray *sortedPlayers = [players sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSInteger first = [(BL_Player *)a playerScore];
NSInteger second = [(BL_Player *)b playerScore];
return [first compare:second options:NSNumericSearch];
}];
两者都返回错误的接收器类型。对整数或 NSInteger 进行比较有什么问题?
【问题讨论】:
-
比较方法适用于 NSNumber 不适用于 int 或 NSInteger
-
...所以任何合理的编译器设置,都不应该编译。
标签: ios objective-c arrays sorting nsarray