NSArray按字母顺序排序

来源:互联网 发布:动态规划算法 编辑:程序博客网 时间:2024/05/20 16:13


    NSArray* unsortedArray = [[NSArray alloc] initWithObjects:@"DAFDA",@"EWRWE",@"VCXVX",@"HSHXC",@"ONSWXC",@"WETCS",@"ACXDS", nil];    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];    NSArray *sortedArray = [unsortedArray sortedArrayUsingDescriptors:[NSArray arrayWithObjects:sortDescriptor,nil]];    NSLog(@"sortedArray:%@",sortedArray);


输出结果如下:

sortedArray:(

    ACXDS,

    DAFDA,

    EWRWE,

    HSHXC,

    ONSWXC,

    VCXVX,

    WETCS

)


0 0
原创粉丝点击