Hik*_*rus 2 predicate filter photos fetch swift
当我发布照片时:
let assetCollections: PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .Any, options: nil)
Run Code Online (Sandbox Code Playgroud)
我得到了几张专辑的结果,所以我可以遍历数组并将它们的标题放在tableView中.
但是:当我使用谓词来过滤并获得例如专辑"Camera Roll"时,结果总是一个空数组:(而且我知道100%确定相机卷存在,因为它使用nil选项获取它)
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "title = %@", "Camera Roll")
let assetCollections: PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .Any, options: fetchOptions)
let album: PHAssetCollection = assetCollections.firstObject as! PHAssetCollection
Run Code Online (Sandbox Code Playgroud)
我已经在线阅读了4种或5种不同的方法,他们都有这个谓词,无论是"title =%@",还是"localizedTitle =%@"或"localizedIdentifier =%@"......我都不知道它.似乎为人们工作,而不是为我工作.编译器在最后一行崩溃,试图"展开一个nil可选值"('cos获取结果为空).为什么一旦包含获取选项,搜索返回nil ???
如果你想要相机胶卷专辑,你可能最好象征性地要求它:
let collections = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .SmartAlbumUserLibrary, options: nil)
Run Code Online (Sandbox Code Playgroud)
该SmartAlbumUserLibrary亚型是你如何让相机胶卷(这并不总是称那).
| 归档时间: |
|
| 查看次数: |
3456 次 |
| 最近记录: |