iOS 数组排序

//给数组模型排序,先根据第一个参数排序,第一个参数相同,则进行第二个参数排序
NSSortDescriptor * eNameDesc = [NSSortDescriptor sortDescriptorWithKey:@"ecityName" ascending:YES];
        
        NSSortDescriptor * groupDesc = [NSSortDescriptor sortDescriptorWithKey:@"groupWord" ascending:YES];
        
        NSArray * descs = [NSArray arrayWithObjects:eNameDesc,groupDesc, nil];
        
        NSArray * array = [_resultDataArray sortedArrayUsingDescriptors:descs];
//给可变数组排序
//金额排序
 NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"DiscountAmount" ascending:NO];
 [self.dataModelArray sortUsingDescriptors:[NSArray arrayWithObject:sort]];
//给数组中的字母排序,a~z
[_indexArray addObjectsFromArray:[arr sortedArrayUsingSelector:@selector(compare:)]];

你可能感兴趣的:(iOS 数组排序)