Select only albums in PHCollectionList

A PHCollectionList

is a folder that can contain any number of albums and / or folders. I am currently collecting collections in the list via PHCollection.fetchCollectionsInCollectionList(list, options: nil)

.

It can return objects of type PHAssetCollection

or PHCollectionList

. I am only interested in the knowledge PHAssetCollection

on this list. In the docs, you can apply a filter predicate using fetch options to return a subset of the data, but I can't see how to use that to get only albums. How do you use PHFetchOptions

to return only PHAssetCollection

to the target PHCollectionList

?

+3


source to share


2 answers


You tried:

    [PHCollectionList fetchCollectionListsWithType:<filterType> subtype:nil optionsnil]

      



If yours <ftilerType>

can be any of PHCollectionListType

:

  • PHCollectionListTypeMomentList - Moments created by the iPhone (essentially all photos grouped into Years and Collections)
  • PHCollectionListTypeFolder - user-created Albums (folders)
  • PHCollectionListTypeSmartFolder - auto-generated iPhone iPhones are automatically generated
0


source


You can use a predicate to specify an album name and use it to retrieve a specific album from a collection.

PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", ABC];

PHFetchResult *collectionsFetchResult = [PHCollection fetchCollectionsInCollectionList:self.collectionList options:fetchOptions];

PHAssetCollection *ABCAlbum = collectionsResult.firstObject;
  NSLog(@"ABC album details: %@", ABCAlbum);

      



Or you can set options to nil and get all the AssetCollections in the list.

    PHFetchResult *collectionsFR = [PHCollection fetchCollectionsInCollectionList:list options:nil];
      if ( collectionsFR.count > 0) {
        for ( PHAssetCollection *collection in collectionsFR) {
          // do something with each album
          NSLog(@"collection is %@", collection);
        }
      }

      

0


source







All Articles