【问题标题】:Fetch PHAssets in sequence按顺序获取 PHAsset
【发布时间】:2020-09-01 23:21:46
【问题描述】:

我正在尝试通过传递本地标识符数组从照片库中获取资产。但是输出的顺序不同。我的应用要求我按顺序获取它们。这就是我使用它的方式

let fetchedResults = PHAsset.fetchAssets(withLocalIdentifiers: videosInLibrary, options: nil)
fetchedResults.enumerateObjects { (asset:PHAsset , count:Int, stop:UnsafeMutablePointer<ObjCBool>) in

我们可以做些什么来按我传递的本地标识符的顺序获取它们。

【问题讨论】:

  • 您为什么不将所有生成的 PHAsset 累积到一个数组中,然后按照您喜欢的顺序放置它?
  • 我最终也做了同样的事情。谢谢。

标签: ios swift phasset


【解决方案1】:

它是数据库,所以按存储返回,但你可以在本地完成:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-24
    • 2019-02-13
    • 1970-01-01
    • 2022-01-16
    • 2017-03-03
    • 2013-09-10
    • 2019-05-10
    • 1970-01-01
    相关资源
    最近更新 更多