(ios开发小技巧)对存在docment中的文件进行排序

NSFileManager* manager = [NSFileManager defaultManager];
NSArray *paths = [manager subpathsAtPath:KDocumentPath];
//NSArray* fileList = [manager contentsOfDirectoryAtPath:KDocumentPath error:nil];
NSArray* fileList = [paths sortedArrayUsingComparator:^NSComparisonResult(id_Nonnull obj1, id_Nonnull obj2) {
NSString *firstUrl = [KDocumentPath stringByAppendingPathComponent:obj1]; //获取前一个文件完整路径
NSString *secondUrl = [KDocumentPath stringByAppendingPathComponent:obj2]; //获取后一个文件完整路径
NSDictionary *firstFileInfo = [manager attributesOfItemAtPath:firstUrl error:nil]; //获取前一个文件信息
【(ios开发小技巧)对存在docment中的文件进行排序】NSDictionary *secondFileInfo = [manager attributesOfItemAtPath:secondUrl error:nil]; //获取后一个文件信息
id firstData = https://www.it610.com/article/[firstFileInfo objectForKey:NSFileModificationDate]; //获取前一个文件修改时间
id secondData = https://www.it610.com/article/[secondFileInfo objectForKey:NSFileModificationDate]; //获取后一个文件修改时间
return ![firstData compare:secondData]; //降序
}];

    推荐阅读