1

I am using an NSSortDescriptor to sort an array as follows:

NSSortDescriptor *titleDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects: titleDescriptor, nil]; 

self.items = (NSMutableArray*)[self.items sortedArrayUsingDescriptors:sortDescriptors];

Which works great. What I would like to do is have one specific "title" (from which I know the exact string) always at the top of the list, and then have the NSSortDescriptor's sort the rest of the titles alphabetically below said title. What is the syntax to accomplish this using NSSortDescriptor?

1 Answer 1

3

You should use one of the other methods like sortedArrayUsingSelector: to gain this level of control.

Also, don't just cast the result to a mutable array. If the array is mutable, use the method which sorts the mutable array. If you use the method to create a new array, make sure it is mutable by calling mutableCopy on the result.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.