2012-06-20 22 views
22

Mam sortowania jest NSMutableArray następująco:NSMutableArray Sortowanie - sprawa niewrażliwe

NSSortDescriptor *sortDescriptor; 
    sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:str_key ascending:bool_asc_desc] autorelease]; 
    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; 
    NSArray *sortedArray; 
    sortedArray = [ads_printers_array sortedArrayUsingDescriptors:sortDescriptors]; 

Problemem jest to, że jest to sprawa wrażliwa, i chciałbym, aby to sprawa niewrażliwe. Jak mogę to zrobić? Próbowałem czytania docs i znalazłem coś takiego:

sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:str_key ascending:bool_asc_desc selector: @selector(caseInsensitiveCompare)] autorelease]; 

Jednakże, nie mam pojęcia, co I powinny być wprowadzenie argumentu selektora. Dzięki!

+1

możliwe duplikat [Chcę posortować tablicę używając NSSortDescriptor] (http://stackoverflow.com/questions/5542762/i- chcesz-sortować-tablica-używając-nssortdescriptor) –

+0

Zamówienie następujące post: http://stackoverflow.com/a/5542888/200272 –

+1

Dziękuję, dla każdego zainteresowanego metody selektora, którego użyłem jest (localizedCaseInsensitiveCompare :) . Twoje zdrowie! – Kevin

Odpowiedz

39
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:str_key 
    ascending:YES selector:@selector(caseInsensitiveCompare:)]; 

ads_printers_array = [ads_printers_array sortedArrayUsingDescriptors:[NSArray 
    arrayWithObject:sortDescriptor]]; 
+0

To rozwiązanie sprawdziło się –

0

do szybkiego, wykonaj następujące czynności:

let sortDescriptor = NSSortDescriptor(key: sortDescriptorKey, ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:)))

Powiązane problemy