5

A PHCollectionList is a folder that could contain any number of albums and/or folders. I am currently fetching the collections within the list via PHCollection.fetchCollectionsInCollectionList(list, options: nil).

This could return objects of type PHAssetCollection or PHCollectionList. I am only interested in knowing of the PHAssetCollections in that list. The docs state you can apply a filter predicate using the fetch options in order to return a subset of the data, but I don't see how I would use that in order to only get albums. How do you use PHFetchOptions in order to return only PHAssetCollections in a given PHCollectionList?

Jordan H
  • 52,571
  • 37
  • 201
  • 351

2 Answers2

1

Have you tried:

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

Where your <ftilerType> could be anything from PHCollectionListType:

  • PHCollectionListTypeMomentList - Moments created by iPhone (essentially all photos grouped into Year and Collections)
  • PHCollectionListTypeFolder - user created Albums (folders)
  • PHCollectionListTypeSmartFolder - Smart folders created by the iPhone automatically
snowbound
  • 1,692
  • 2
  • 21
  • 29
0

You can use predicate to specify the album's name and use it to fetch specific Album from the collectionList.

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 put nil in options and get all of 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);
        }
      }
Ohmy
  • 2,201
  • 21
  • 24