I'm trying to build a simply photo picker that has two options for now: Recents and Favorites. What I'm doing is trying to get all the photos by the creationDate
however this is giving back images in the wrong order in my data source. There's photos from years ago at the beginning of the data source, and photos that are less than a few minutes old scattered throughout. I think the issue is that I need to tell the main fetchResult the sort order first, however I don't think it's possible: Unsupported sort descriptor in fetch options: (creationDate, ascending, compare:
I'd appreciate any help offered. 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];
}
}
}
}
I figured this out on my own, here is my solution: