Ios 按顺序提取阶段集
我试图通过传递一个本地标识符数组从照片库中获取资产。但输出的顺序不同。我的应用程序要求我按顺序获取它们。这就是我使用它的方式Ios 按顺序提取阶段集,ios,swift,phasset,Ios,Swift,Phasset,我试图通过传递一个本地标识符数组从照片库中获取资产。但输出的顺序不同。我的应用程序要求我按顺序获取它们。这就是我使用它的方式 let fetchedResults = PHAsset.fetchAssets(withLocalIdentifiers: videosInLibrary, options: nil) fetchedResults.enumerateObjects { (asset:PHAsset , count:Int, stop:UnsafeMutablePointer<Ob
let fetchedResults = PHAsset.fetchAssets(withLocalIdentifiers: videosInLibrary, options: nil)
fetchedResults.enumerateObjects { (asset:PHAsset , count:Int, stop:UnsafeMutablePointer<ObjCBool>) in
let fetchedResults=PHAsset.fetchAssets(带有LocalIdentifier:videosInLibrary,选项:nil)
fetchedResults.enumerateObjects{(资产:PHAsset,计数:Int,停止:UnsafemeutablePointer)位于
我们可以做些什么来按照我传递的本地标识符的顺序获取它们。这是数据库,所以以存储方式返回,但您可以在本地执行:
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[$0] }
let fetchedResults=PHAsset.fetchAssets(带有LocalIdentifier:videosInLibrary,选项:nil)
var tmpCache=[String:PHAsset]()
fetchedResults.enumerateObjects{(资产:PHAsset,计数:Int,停止:UnsafemeutablePointer)位于
tmpCache[asset.localIdentifier]=资产
}
let results=videosInLibrary.compactMap{tmpCache[$0]}
为什么不将所有生成的相位集累加到一个数组中,然后按您喜欢的顺序排列呢?我最后也这样做了。谢谢。