gpt4 book ai didi

ios - 如何按日期排序数组?

转载 作者:行者123 更新时间:2023-11-28 18:57:23 24 4
gpt4 key购买 nike

我有一个这样格式的数组:

 <__NSArrayM 0x7fc013d31940>(
{
description = "";
link = "";
pubDate = "Tue, 16 Jun 2015 07:36:00 +0200";
title = "";
},
{
description = "";
link = "";
pubDate = "Mon, 15 Jun 2015 21:18:00 +0200";
title = "";
}
{
description = "";
link = "";
pubDate = "Tue, 16 Jun 2015 11:27:00 +0200";
title = "";
},

我想通过 pudDate 订购。这样做的正确方法是什么?

最佳答案

像这样:

NSDateFormatter *df = [NSDateFormatter new];
df.dateFormat = @"EEE, d MMM yyyy HH:mm:ss ZZZ";
NSArray *newArr = [arr sortedArrayWithOptions:0 usingComparator:^NSComparisonResult(id obj1, id obj2) {
NSDate *date1 = [df dateFromString:obj1[@"pubDate"]];
NSDate *date2 = [df dateFromString:obj2[@"pubDate"]];
return [date1 compare:date2];
}];

下次使用搜索:How to sort an NSMutableArray with custom objects in it?

关于ios - 如何按日期排序数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30866627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com