user1020317
user1020317

Reputation: 654

Has xcode 4.5 changed sortedArrayUsingComparator + blocks?

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.

Upvotes: 2

Views: 2015

Answers (1)

Ramy Al Zuhouri
Ramy Al Zuhouri

Reputation: 21996

You forgot the return value type:

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

Upvotes: 6

Related Questions