我有一个以对象为日期的可变数组,现在我想从数组中获取最大日期。
NSMutableArray *arrDates = [[NSMutableArray alloc]init];
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"yyyy-MM-dd"];
for (int i = 0; i<dateArray2.count; i++)
{
[arrDates addObject:[df dateFromString:dateArray2[i]]];
}
NSLog(@"%@",arrDates);
NSDate *maxDate=[arrDates valueForKeyPath:@"@max.date"];
NSLog(@"max date is %@",maxDate);
}
在执行应用程序时终止..任何人都可以帮助我...谢谢
最佳答案
您可以使用,
NSDate *maxDate = [dateArray valueForKeyPath:@"@max.self"];
这将为您提供数组中最大的日期。
阅读更多https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/CollectionOperators.html
关于ios - 从 objective-c 中的数组中找到最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38090436/