Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用UnixTime标记对数组进行排序_Ios_Iphone_Sorting_Nsarray - Fatal编程技术网

Ios 如何使用UnixTime标记对数组进行排序

Ios 如何使用UnixTime标记对数组进行排序,ios,iphone,sorting,nsarray,Ios,Iphone,Sorting,Nsarray,我想按时间对数组排序。但问题是,时间以UNIX时间戳的形式存在于另一个数组(数组的子数组)中 这是格式。请任何人帮我整理一下 ( group, "The Comic Corner", "" ), ( group, "Home Alone", "" ), ( group, "Romantic Movies", "" ), ( group, "Thriller Movies",

我想按时间对数组排序。但问题是,时间以UNIX时间戳的形式存在于另一个数组(数组的子数组)中

这是格式。请任何人帮我整理一下

    (
    group,
    "The Comic Corner",
    ""
),
    (
    group,
    "Home Alone",
    ""
),
    (
    group,
    "Romantic Movies",
    ""
),
    (
    group,
    "Thriller Movies",
    ""
),
    (
    group,
    Badminton,
    ""
),
    (
    group,
    "Celebrity Gossip",
    ""
),
    (
    group,
    "Dark Night",
    ""
),
    (
    group,
    "Graphics Designer",
    ""
),
    (
    group,
    "I Just Wanna....",
    ""
),
    (
    group,
    Religion,
    ""
),
    (
    group,
    "English Movies",
    ""
),
    (
    group,
    "Music World",
    ""
),
    (
    group,
    "Actions Movies",
    ""
),
    (
    group,
    "Bed & Breakfast",
    ""
),
    (
    group,
    "Strategic Games",
    ""
),
    (
    group,
    "Beer Lovers",
    ""
),
    (
    group,
    Hackers,
    ""
),
    (
    group,
    "Darkroom-Darkroom",
    ""
),
    (
    group,
    "Arcade Games",
    ""
),
    (
    group,
    "Hindi Movies",
    ""
),
    (
    mood,
    Anxious,
    1386749684146
),
    (
    "profilepic_time",
    1386545975408
),
    (
    "status_msg",
    " *z32_ hell0",
    1386635654457
),
    (
    Broadcast,
    3,
    11,
    1372945566365
),
    (
    Broadcast,
    3,
    11,
    3
),
    (
    Broadcast,
    3,
    11,
    3
),
    (
    Broadcast,
    3,
    11,
    1372858799160
),
    (
    Broadcast,
    6,
    11,
    1372920363550
),
    (
    Broadcast,
    6,
    30,
    1373012360303
),
    (
    Broadcast,
    6,
    30,
    1373015204935
),
    (
    Broadcast,
    6,
    30,
    1373018547181
),
    (
    Broadcast,
    6,
    30,
    1373018768064
),
    (
    Broadcast,
    7,
    37,
    1373025360112
),
    (
    Broadcast,
    3,
    37,
    1373031270639
),
    (
    Broadcast,
    3,
    42,
    1373868972980
),
    (
    Broadcast,
    3,
    29,
    1372936645430
),
    (
    Broadcast,
    3,
    29,
    1372935983470
),
    (
    Broadcast,
    3,
    101,
    1374150527293
),
    (
    bulletin,
    "dbxjsbxdijxjdjxichdjdixhdbdjx hdjdbdh",
    1382331040766
),
    (
    bulletin,
    "aaabbb ccc dddd eee ffff",
    1382510132316
),
    (
    bulletin,
    "dvxishhxxbbosihdjxibididhxososjshsisos dijfjeosksn osjdjkd",
    1382510521856
),
    (
    bulletin,
    tsotdo,
    1382707279159
),
    (
    bulletin,
    84saurzuzri,
    1382707293764
),
    (
    bulletin,
    aiaktsktzyodld,
    1382707305875
),
    (
    bulletin,
    uarsistoso,
    1382707326326
),
    (
    bulletin,
    2e58e8etisististi,
    1382707335278
),
    (
    bulletin,
    ztkzktzgtkktotk,
    1382707484453
),
    (
    bulletin,
    ztkzktzgtkktotk9e85a4a47a48a37ariz,
    1382707491619
),
    (
    bulletin,
    "dbxidj didcxj",
    1384173984019
),
    (
    bulletin,
    "testing testing testing testing",
    1384589761276
),
    (
    bulletin,
    "testing testing testing testing",
    1384589772960
),
    (
    bulletin,
    "testing testing testing testing",
    1384589788706
),
    (
    bulletin,
    "testing testing testing testing",
    1384589822861
),
    (
    bulletin,
    "testing testing testing testing",
    1384589871332
),
    (
    bulletin,
    "testing testing testing testing",
    1384589875364
),
    (
    bulletin,
    "testing testing testing testing",
    1384589910927
),
    (
    bulletin,
    hey,
    1384589984774
),
    (
    bulletin,
    "heya ",
    1384590016235
),
    (
    bulletin,
    ok,
    1384597237610
),
    (
    bulletin,
    "hey ",
    1384605812061
),
    (
    bulletin,
    fhjfs,
    1384757502287
),
有些数组有时间戳,有些数组没有时间戳

这对我来说很复杂。有人能帮我吗
谢谢

您需要指定一个自定义比较器块,如下所示(您需要根据数据结构调整索引):

如果希望非时间戳记录显示在时间戳记录之前,可以将
sensorderedescending
更改为
sensorderedescending


此外,我建议您避免将数据存储在
NSArray
s的
NSArray
中,并为您的项目创建适当的(如果需要,可以定义自己的排序功能)。

查看NSArray的任何“sortedarray使用…”方法,以及“sortUsing…:NSMutableArray的方法。我通常发现,对于我的脆弱的大脑来说,使用“…UsingFunction”风格并为比较器定义一个C风格的函数是最简单的,但其他人喜欢花哨的块东西。它不是从nsmutable数组中给出的排序方法中进行排序。我想我们必须手动排序。但是我找不到工作的确切逻辑。它是排序的,但我不知道排序字符串所用的参数是什么。在我的下一个评论中(组,“名人八卦”,“签入位置”,“公告,“测试”,“登记处”,138458875364),(广播,3,29,1372936645430),(团体,“动作电影”,“登记处”,”),(广播,6,30,1373018768064),(组,“黑夜”,“登记处”,“登记处”),如何正确排序日期请帮助meI查看各种记录具有不同数量的元素。您是否承诺时间戳在哪里,以及如何知道记录中是否不存在时间戳?如果我理解正确,则最后一个对象是
““
或时间戳本身。我已经根据那个猜测编辑了我的答案。
NSArray *array = @[@[@"a", @456], @[@"b", @123], @[@"c", @""]];

NSArray *sorted = [array sortedArrayUsingComparator:^NSComparisonResult(NSArray *a, NSArray *b) {
  if ([a.lastObject isKindOfClass:[NSNumber class]] &&
      [b.lastObject isKindOfClass:[NSNumber class]]) {
    return [a.lastObject compare:b.lastObject];
  }
  return NSOrderedAscending;
}];

NSLog(@"%@", sorted);