Return type “NSComparaisonResult” after the XCode update

空扰寡人 提交于 2019-12-11 10:00:56

问题


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]; break;

I have this error message:

"Return type 'NSComparaisonResult' (aka 'NSComparaisonResult') must match previous return type 'NSIntger' (aka 'int')"

after each code line:

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

Would you have an idea?


回答1:


Explicitly specify the return type:

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

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.



来源:https://stackoverflow.com/questions/13324079/return-type-nscomparaisonresult-after-the-xcode-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!