【发布时间】:2017-10-10 11:23:46
【问题描述】:
我正在获取用户库中存在的所有 smartAlbum。 我使用的代码是这样的:
var smartAlbums: PHFetchResult<PHAssetCollection>!
override func viewDidLoad() {
super.viewDidLoad()
let options = PHFetchOptions()
options.predicate = NSPredicate(format: "estimatedAssetCount > 0")
options.sortDescriptors = [NSSortDescriptor(key: "localizedTitle", ascending: true)]
smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: options)
我将在表格视图中显示结果,并使用它来计算部分中的行数:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Section(rawValue: section)! {
case .allPhotos: return 1
case .smartAlbums: return smartAlbums.count
case .userCollections: return userCollections.count
}
}
一切正常...但 smartAlbums 的提取结果也提取了零媒体的专辑。基本上它会获取所有专辑。似乎谓词它没有被考虑在内。 相同的谓词应用于 userCollections 并且效果很好。
userCollections = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .albumRegular, options: options) // this works fine
有没有办法只获取包含至少一种媒体的 smartAlbums?
谢谢!
【问题讨论】:
标签: ios swift fetch photosframework