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.

2
  • 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? Commented May 12, 2014 at 3: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. Commented May 12, 2014 at 4:18

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.