如何按大小

时间:2017-03-02 07:01:38

标签: ios objective-c

我有数千个PHAssets数组(arrayOfAsset),我知道如何按创建日期对该数组进行排序。

[[arrayOfAsset objectAtIndex:j1 ] sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]];

但我不知道如何按资产大小对该数组进行排序。

1 个答案:

答案 0 :(得分:0)

您好,您可以使用pixelWidthpixelHeight根据尺寸进行粗略排序。假设只有照片。对于视频,您需要在排序中包含duration

NSSortDescriptor *sortByWidth = [NSSortDescriptor sortDescriptorWithKey:@"pixelWidth" ascending:YES];
NSSortDescriptor *sortByHeight = [NSSortDescriptor sortDescriptorWithKey:@"pixelHeight" ascending:YES];
[[arrayOfAsset objectAtIndex:j1] sortUsingDescriptors:@[sortByWidth,sortByHeight]];