返回类型为"NSComparaisonResult"; XCode更新后 [英] Return type "NSComparaisonResult" after the XCode update
问题描述
我有一个与此处概述的问题类似的问题: xcode 4.5是否更改了sortedArrayUsingComparator +块?
I have a problem similar to the one outlined here: Has xcode 4.5 changed sortedArrayUsingComparator + blocks?
int index = [AAjouter indexOfObject:match inSortedRange:NSMakeRange(0, [AAjouter count]) options:NSBinarySearchingInsertionIndex usingComparator:^(id obj1, id obj2) {
Match *match1 = (Match *) obj1;
Match *match2 = (Match *) obj2;
if ([match1.matchDate isEqualToDate:match2.matchDate]) {
if ([match1.paysCompetition isEqualToString:match2.paysCompetition]) {
if ([[NSNumber numberWithInt:match1.ordreCompetition] isEqualToNumber:[NSNumber numberWithInt:match2.ordreCompetition]]) {
if ([match1.equipeANom isEqualToString:match2.equipeANom]) {
return NSOrderedSame;
}
else {
return [match1.equipeANom compare:match2.equipeANom];
}
}
else {
return [[NSNumber numberWithInt:match1.ordreCompetition] compare:[NSNumber numberWithInt:match2.ordreCompetition]];
}
}
else {
return [match1.paysCompetition compare:match2.paysCompetition];
}
}
else {
return [match1.matchDate compare:match2.matchDate];
}
}];
[AAjouter insertObject:match atIndex:index]; 休息;
[AAjouter insertObject:match atIndex:index]; break;
我收到此错误消息:
返回类型'NSComparaisonResult'(aka'NSComparaisonResult')必须 匹配先前的返回类型'NSIntger'(aka'int')"
"Return type 'NSComparaisonResult' (aka 'NSComparaisonResult') must match previous return type 'NSIntger' (aka 'int')"
每行代码后:
return [[NSNumber numberWithInt:match1.ordreCompetition] compare:[NSNumber numberWithInt:match2.ordreCompetition]];
return [match1.paysCompetition compare:match2.paysCompetition];
return [match1.matchDate compare:match2.matchDate];
你有个主意吗?
推荐答案
明确指定返回类型:
^NSComparisonResult(id obj1, id obj2) { ...
编译器通常会推断出该块的返回类型,但在某些情况下,可能会感到困惑.我怀疑这可能与返回枚举NSOrderedSame
有关,在较早版本的编译器中,该枚举类型为int
.
The compiler usually infers the return type of the block, but in some cases, it can get confused. I suspect it might have to do with returning the enum NSOrderedSame
, which, on older versions of the compiler, would be type int
.
这篇关于返回类型为"NSComparaisonResult"; XCode更新后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!