我已阅读有关该主题的所有答案,但我的数组仍未排序。请帮我解决这个问题。代码有什么问题?提前致谢。
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filename error:NULL];
NSDate *date = [attributes fileCreationDate];
NSMutableArray *datesList = [[NSMutableArray alloc] init];
[datesList addObject:date];
NSArray *sortedArray = [[NSArray alloc] init];
sortedArray = [datesList sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
if ([obj1 date] > [obj2 date])
{
return (NSComparisonResult)NSOrderedAscending;
}
if ([obj1 date] < [obj2 date])
{
return (NSComparisonResult)NSOrderedDescending;
}
return (NSComparisonResult)NSOrderedSame;
}];
NSLog(@"sortedarray:%@",sortedArray);