0

I am sorting an array of custom winery objects by a name attribute.

wineryNames = [NSMutableArray arrayWithArray:[wineryNames sortedArrayUsingComparator:^(Winery *a, Winery *b){
    return [a.getName compare:b.getName options:NSCaseInsensitiveSearch];
}]];

I am receiving an error on the return line and the log says 'unrecognized selector'. I have no idea why this isn't working.

  • Is `wineryNames` definitely an array containing `Winery` objects? And, what does the `@interface` declaration for the Winery class look like? Does it have a method or property called `getName`? – Mike Mertsock May 12 '14 at 03:40
  • Thank you so much esker. It was an array containing NSString objects, not Winery objects. I don't know why I didn't see it, I guess it was just make my head hurt type code and I made a few other classes with code similar to what I posted. But thank you - it works now. – user3626968 May 12 '14 at 04:18

1 Answers1

2

I think this will do the job:

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name"
                                                                 ascending:YES
                                                                  selector:@selector(caseInsensitiveCompare:)];
NSArray *sortedArray = [wineryNames sortedArrayUsingDescriptors:@[sortDescriptor]];

More info Here!

Community
  • 1
  • 1
Logan
  • 52,262
  • 20
  • 99
  • 128