小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

NSSortDescriptor使用注意以及直接排序字符串數(shù)組

 昵稱v8JFa 2016-06-17

NSSortDescriptor 指定用于對象數(shù)組排序的對象的屬性。

如果是Employee對象需要按照name來排序,就生成下面的descriptor

NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:name ascending:YES];

如果需要多個排序,比如先按name排序,再按入職日期排序。那就創(chuàng)建兩個descriptor

NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:hireDate ascending:YES];

兩個descriptor放到數(shù)組里一起傳給需要排序的數(shù)組。


如果對象就是NSString,就是字符串數(shù)組排序,那更簡單了,sortdescriptor的key直接指定為nil,就直接排序?qū)ο?,而不是對象的某一個屬性了。

    NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];

    NSArray *descriptors = [NSArray arrayWithObject:descriptor];

    NSArray *myDataArray = [NSArray arrayWithObjects:@"what", @"xero", @"highligth", @"mountain", @"Victory", @"Balance", nil];

    NSArray *resultArray = [myDataArray sortedArrayUsingDescriptors:descriptors];

    NSLog(@"%@", resultArray);


NSArray 使用sortedArrayUsingDescriptors,返回排序好的數(shù)組。

NSMutableArray可以直接使用sortUsingDescriptors,對數(shù)組本身排序。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多