Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top