1

我有一个类似于此处概述的问题: 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]; 休息;

我有这个错误信息:

“返回类型'NSComparaisonResult'(又名'NSComparaisonResult')必须匹配先前的返回类型'NSIntger'(又名'int')”

在每个代码行之后:

return [[NSNumber numberWithInt:match1.ordreCompetition] compare:[NSNumber numberWithInt:match2.ordreCompetition]]; 
return [match1.paysCompetition compare:match2.paysCompetition]; 
return [match1.matchDate compare:match2.matchDate];

你有什么想法吗?

4

1 回答 1

3

显式指定返回类型:

^NSComparisonResult(id obj1, id obj2) { ...

编译器通常会推断块的返回类型,但在某些情况下,它可能会混淆。我怀疑这可能与返回 enumNSOrderedSame有关,在旧版本的编译器上,它是 type int

于 2012-11-12T09:55:11.523 回答