Roi*_*lia 1 nspredicate ios swift photosframework phasset
我正在尝试仅从设备相册中获取“实时照片”。我找到了这个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];
Run Code Online (Sandbox Code Playgroud)
迅速:
fetchOptions.predicate = NSPredicate(format: "mediaSubtype == %ld", PHAssetMediaSubtype.PhotoLive)
Run Code Online (Sandbox Code Playgroud)
抛出编译错误:
Argument type 'PHAssetMediaSubtype' does not conform to expected type 'CVarArgType'
Any suggestions?
Run Code Online (Sandbox Code Playgroud)
您无法为该方法提供Swift枚举值-它需要很长的时间(如%ld格式字符串所暗示),因此请使用
fetchOptions.predicate = NSPredicate(format: "mediaSubtype == %ld", PHAssetMediaSubtype.PhotoLive.rawValue)
Run Code Online (Sandbox Code Playgroud)
访问枚举值的基础整数值
| 归档时间: |
|
| 查看次数: |
1055 次 |
| 最近记录: |