Has xcode 4.5 changed sortedArrayUsingComparator + blocks?

大兔子大兔子 提交于 2019-12-12 19:04:02

问题


Just updated xcode to 4.5 and I'm receiving an error in one of my iOS apps which I wasn't getting previously. Problem was not occurring before the update.

Basically, I have an array that needs sorting, based on some other irrelevant tests..

NSArray *sortedArray = [arrayFiles sortedArrayUsingComparator:^(id a, id b) {
    NSString *first = [(PPFile*)a name];
    NSString *second = [(PPFile*)b name];

    if ([a isFileAvailableForRead] && ![b isFileAvailableForRead]) {

        return  NSOrderedAscending;
    }else if(![a isFileAvailableForRead] && [b isFileAvailableForRead]) {

        return  NSOrderedDescending;
    }

    return [first compare:second];

}];

The error is on the last return of the block:

     Return type 'NSComparisonResult' (aka 'enum NSComparisonResult') must match previous type 'NSInteger' (aka 'int') when block literal has unspecified explicit return type

Thanks.


回答1:


You forgot the return value type:

NSArray *sortedArray = [arrayFiles sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
    < your code>
}];


来源:https://stackoverflow.com/questions/12548789/has-xcode-4-5-changed-sortedarrayusingcomparator-blocks

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