簡體   English   中英

Objective C自定義數組排序算法錯誤

[英]Objective C custom array sorting algorithm error

我正在通過name屬性對自定義winery對象的數組進行排序。

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

我在返回行上收到錯誤,日志顯示'無法識別的選擇器'。 我不知道為什么這不起作用。

我認為這將完成這項工作:

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

更多信息在這里!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM