Reputation: 5896
I'm trying to fetch only Live Photos out of the device albums. I found this Objective C code, but for some reason when converting it to Swift to doesn't compile.
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat: @"(mediaSubtype == %ld)", PHAssetMediaSubtypePhotoLive];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey: @"creationDate" ascending: NO]];
PHFetchResult<PHAsset *> *assetsFetchResults = [PHAsset fetchAssetsWithMediaType: PHAssetMediaTypeImage options: options];
Swift:
fetchOptions.predicate = NSPredicate(format: "mediaSubtype == %ld", PHAssetMediaSubtype.PhotoLive)
throws compile error :
Argument type 'PHAssetMediaSubtype' does not conform to expected type 'CVarArgType'
Any suggestions?
Upvotes: 1
Views: 1291
Reputation: 114992
You can't supply a Swift enumeration value to that method - it needs a long (as is implied by the %ld
format string), so use
fetchOptions.predicate = NSPredicate(format: "mediaSubtype == %ld", PHAssetMediaSubtype.PhotoLive.rawValue)
to access the underlying integer value of the enumeration value
Upvotes: 6