I am trying to create a simple photo picker that has two options: Recursions and Favorites. What I am doing is trying to get all the photos using creationDate , but this returns the images in the wrong order in my data source. There are photographs from several years ago at the beginning of the data source, and photographs that are less than a few minutes are scattered everywhere. I think the problem is that I need to first specify the main selection of fetchResult, but I don't think it is possible: Unsupported sort descriptor in fetch options: (creationDate, ascending, compare:
I would appreciate any help. Code:
@property (nonatomic, strong) NSMutableOrderedSet *recentsDataSource; @property (nonatomic, strong) NSMutableOrderedSet *favoritesDataSource; - (void)setup { PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum | PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil]; for (PHAssetCollection *sub in fetchResult) { PHFetchOptions *fetchOptions = [[PHFetchOptions alloc]init]; fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]; PHFetchResult *assetsInCollection = [PHAsset fetchAssetsInAssetCollection:sub options:fetchOptions]; for (PHAsset *asset in assetsInCollection) { [self.recentsDataSource addObject:asset]; if (asset.isFavorite) { [self.favoritesDataSource addObject:asset]; } } } }
source share