ios - PHFetchResult get all photos and sort by date inconsistent -
i'm trying build photo picker has 2 options now: recents , favorites. i'm doing trying photos creationdate
giving images in wrong order in data source. there's photos years ago @ beginning of data source, , photos less few minutes old scattered throughout. think issue need tell main fetchresult sort order first, don't think it's possible: unsupported sort descriptor in fetch options: (creationdate, ascending, compare:
i'd appreciate offered. code:
@property (nonatomic, strong) nsmutableorderedset *recentsdatasource; @property (nonatomic, strong) nsmutableorderedset *favoritesdatasource; - (void)setup { phfetchresult *fetchresult = [phassetcollection fetchassetcollectionswithtype:phassetcollectiontypesmartalbum | phassetcollectiontypealbum subtype:phassetcollectionsubtypeany options:nil]; (phassetcollection *sub in fetchresult) { phfetchoptions *fetchoptions = [[phfetchoptions alloc]init]; fetchoptions.sortdescriptors = @[[nssortdescriptor sortdescriptorwithkey:@"creationdate" ascending:yes]]; phfetchresult *assetsincollection = [phasset fetchassetsinassetcollection:sub options:fetchoptions]; (phasset *asset in assetsincollection) { [self.recentsdatasource addobject:asset]; if (asset.isfavorite) { [self.favoritesdatasource addobject:asset]; } } } }
i figured out on own, here solution:
- (void)setup { self.recentsdatasource = [[nsmutableorderedset alloc]init]; self.favoritesdatasource = [[nsmutableorderedset alloc]init]; phfetchresult *assetcollection = [phassetcollection fetchassetcollectionswithtype:phassetcollectiontypesmartalbum | phassetcollectiontypealbum subtype:phassetcollectionsubtypeany options:nil]; phfetchresult *favoritecollection = [phassetcollection fetchassetcollectionswithtype:phassetcollectiontypesmartalbum subtype:phassetcollectionsubtypesmartalbumfavorites options:nil]; (phassetcollection *sub in assetcollection) { phfetchresult *assetsincollection = [phasset fetchassetsinassetcollection:sub options:nil]; (phasset *asset in assetsincollection) { [self.recentsdatasource addobject:asset]; } } if (self.recentsdatasource.count > 0) { nsarray *array = [self.recentsdatasource sortedarrayusingdescriptors:@[[nssortdescriptor sortdescriptorwithkey:@"creationdate" ascending:no]]]; self.recentsdatasource = [[nsmutableorderedset alloc]initwitharray:array]; } (phassetcollection *sub in favoritecollection) { phfetchresult *assetsincollection = [phasset fetchassetsinassetcollection:sub options:nil]; (phasset *asset in assetsincollection) { [self.favoritesdatasource addobject:asset]; } } if (self.favoritesdatasource.count > 0) { nsarray *array = [self.favoritesdatasource sortedarrayusingdescriptors:@[[nssortdescriptor sortdescriptorwithkey:@"creationdate" ascending:no]]]; self.favoritesdatasource = [[nsmutableorderedset alloc]initwitharray:array]; } }
Comments
Post a Comment