我正在尝试从设备相册中仅提取实时照片。 我找到了这个Objective C代码,但出于某种原因将其转换为Swift时无法编译。
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];
夫特:
fetchOptions.predicate = NSPredicate(format: "mediaSubtype == %ld", PHAssetMediaSubtype.PhotoLive)
抛出编译错误:
Argument type 'PHAssetMediaSubtype' does not conform to expected type 'CVarArgType'
Any suggestions?
答案 0 :(得分:4)
您无法为该方法提供Swift枚举值 - 它需要很长(如%ld
格式字符串所暗示的那样),因此请使用
fetchOptions.predicate = NSPredicate(format: "mediaSubtype == %ld", PHAssetMediaSubtype.PhotoLive.rawValue)
访问枚举值的基础整数值