按顺序获取 PHAssets
Fetch PHAssets in sequence
我正在尝试通过传递本地标识符数组从照片库中获取资源。但是输出的顺序不一样。我的应用程序要求我在 sequence.This 中获取它们,这就是我使用它的方式
let fetchedResults = PHAsset.fetchAssets(withLocalIdentifiers: videosInLibrary, options: nil)
fetchedResults.enumerateObjects { (asset:PHAsset , count:Int, stop:UnsafeMutablePointer<ObjCBool>) in
我们能做些什么来按照我传递的本地标识符的顺序获取它们吗?
它是数据库,因此按存储的形式返回,但您可以在本地执行:
let fetchedResults = PHAsset.fetchAssets(withLocalIdentifiers: videosInLibrary, options: nil)
var tmpCache = [String: PHAsset]()
fetchedResults.enumerateObjects { (asset:PHAsset , count:Int, stop:UnsafeMutablePointer<ObjCBool>) in
tmpCache[asset.localIdentifier] = asset
}
let results = videosInLibrary.compactMap { tmpCache[[=10=]] }
我正在尝试通过传递本地标识符数组从照片库中获取资源。但是输出的顺序不一样。我的应用程序要求我在 sequence.This 中获取它们,这就是我使用它的方式
let fetchedResults = PHAsset.fetchAssets(withLocalIdentifiers: videosInLibrary, options: nil)
fetchedResults.enumerateObjects { (asset:PHAsset , count:Int, stop:UnsafeMutablePointer<ObjCBool>) in
我们能做些什么来按照我传递的本地标识符的顺序获取它们吗?
它是数据库,因此按存储的形式返回,但您可以在本地执行:
let fetchedResults = PHAsset.fetchAssets(withLocalIdentifiers: videosInLibrary, options: nil)
var tmpCache = [String: PHAsset]()
fetchedResults.enumerateObjects { (asset:PHAsset , count:Int, stop:UnsafeMutablePointer<ObjCBool>) in
tmpCache[asset.localIdentifier] = asset
}
let results = videosInLibrary.compactMap { tmpCache[[=10=]] }