Getting Max Date from NSArray, KVC

后端 未结 2 1587
夕颜
夕颜 2021-01-03 06:31

I\'ve got an array of NSDates and I\'d like to grab the largest NSDate from the array. While i could always sort them and grab the first/last, is there a way to do this with

2条回答
  •  悲&欢浪女
    2021-01-03 07:16

    Agree with @SeanDanzeiser. To be more specific, here's a ~70 byte one-liner:

    // if dateArray is the array of dates ...
    NSDate *maxDate = [[dateArray sortedArrayUsingSelector:@selector(compare:)] lastObject];
    

提交回复
热议问题