Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 按顺序提取阶段集_Ios_Swift_Phasset - Fatal编程技术网

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]}

为什么不将所有生成的相位集累加到一个数组中,然后按您喜欢的顺序排列呢?我最后也这样做了。谢谢。