13

I cannot figure out the proper format necessary to define a predicate for an instance of PHFetchOptions. I've tried so many combinations but they either do not compile or no assets are returned.

The goal is to get only the photos (no videos) in a given collection:

let options = PHFetchOptions()
options.predicate = NSPredicate(format: "mediaType = %i", "PHAssetMediaType.Image")
assetsFetchResults = PHAsset.fetchAssetsInAssetCollection(assetCollection, options: options)

I've tried all combinations of ==, %d, %@, PHAssetMediaTypeImage, "PHAssetMediaTypeImage", PHAssetMediaType.Image, etc.

Jordan H
  • 45,794
  • 29
  • 162
  • 306
  • 3
    You can also use the function `PHAsset.fetchAssetsWithMediaType(_ mediaType: PHAssetMediaType, options options: PHFetchOptions!)`, which might be a more direct way of getting photos only. – bcattle Apr 29 '15 at 20:36

1 Answers1

24
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.Image.rawValue)

Of course I figure it out, right after posting. ;)

Jordan H
  • 45,794
  • 29
  • 162
  • 306