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