我已经下载了适用于 iOS 和 Android 的“Spika”脚本,但遇到了以下问题。尝试编译时出现以下错误:
Incompatible block pointer types sending 'int (^)(ModelMessage *__strong, ModelMessage *__strong)' to parameter of type 'NSComparator' (aka 'NSComparisonResult (^)(__strong id, __strong id)')
我试图通过将其更改为 NSComparisonResult 来解决此问题,但似乎无法理解问题所在。
代码如下:
NSMutableArray *removeTarget = [[NSMutableArray alloc] init];
for(int i = 0; i < [result count] ; i++){
ModelMessage *message = [result objectAtIndex:i];
if(message.valid == NO)
[removeTarget addObject:message];
}
for(int ii = 0; ii < [removeTarget count] ; ii++){
[result removeObject:[removeTarget objectAtIndex:ii]];
}
NSArray *sortedAry = [result sortedArrayUsingComparator:^(ModelMessage *a, ModelMessage *b) {
return a.modified> b.modified;
}];
int fetchNum = PagingMessageFetchNum;
if(fetchNum > sortedAry.count)
fetchNum = sortedAry.count;
return sortedAry;
//return [sortedAry subarrayWithRange:NSMakeRange(0, fetchNum)];
}
问题出在:
NSArray *sortedAry = [result sortedArrayUsingComparator:^(ModelMessage *a, ModelMessage *b) {
return a.modified> b.modified;
任何帮助将不胜感激。谢谢大家。
Best Answer-推荐答案 strong>
您不应该像上面的代码那样返回 BOOL 结果。
结果必须是 NSComparisonResult 类型,即枚举
enum {
NSOrderedAscending = -1,
NSOrderedSame,
NSOrderedDescending
};
在你的情况下,排序 block 应该是这样的
NSArray *sortedAry = [result sortedArrayUsingComparator:^(ModelMessage *a, ModelMessage *b) {
if(a.modified<b.modified)
return NSOrderedAscending;
else if(a.modified>b.modified)
return NSOrderedDescending;
else
return NSOrderedSame;
}];
关于ios - 斯皮卡-iOS : "incompatible block pointer types",我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/26051244/
|