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.
In Swift, constructors skip the "blahWith…" part and just use the class name as a function and then go straight to the arguments, so [NSPredicate predicateWithFormat: …] would become NSPredicate(format: …) . (For another example, [NSArray arrayWithObject: …] would become NSArray(object: …) .
A definition of logical conditions for constraining a search for a fetch or for in-memory filtering.
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.Image.rawValue)
Of course I figure it out, right after posting. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With