NSArray *temp;
[temp sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
NSDictionary *temp1 = obj1;
NSDictionary *temp2 = obj2;
if (temp2[@"addtime"] > temp1[@"addtime"]) return (NSComparisonResult)NSOrderedAscending;
else return (NSComparisonResult)NSOrderedDescending;
}];
//对数据时间 冒泡排序
for (NSInteger i = 0; i < netArray.count; i ++)
{
for (NSInteger j = 1; j < netArray.count - i; j ++)
{
NSString *front = netArray[j - 1][@"addtime"];
NSString *behind = netArray[j][@"addtime"];
if ([front compare:behind] == NSOrderedDescending)
{
NSDictionary *temp = netArray[j - 1];
[netArray replaceObjectAtIndex:j - 1 withObject:netArray[j]];
[netArray replaceObjectAtIndex:j withObject:temp];
}
}
}
数组排序
最新推荐文章于 2016-06-03 09:36:52 发布