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];
}
}
}
數組排序
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.