gpt4 book ai didi

ios - Spika-iOS : "incompatible block pointer types"

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:47 25 4
gpt4 key购买 nike

我已经下载了适用于 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;

如有任何帮助,我们将不胜感激。谢谢大家。

最佳答案

您不应像上面的代码那样返回 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 - Spika-iOS : "incompatible block pointer types",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26051244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com