首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >过滤PHAssetCollection中的矩

过滤PHAssetCollection中的矩
EN

Stack Overflow用户
提问于 2017-12-05 00:21:12
回答 1查看 585关注 0票数 3

使用iOS 11 / Swift 4,我试图从一个图片库中过滤出一些瞬间。我只想要Places。使用nil选项检索moments集合,我得到了13个moments,其中8个moments的标题(location)为非空。当我使用一个简单的谓词localizedTitle != nil执行fetch时刻时,结果总是为零。用空的String ("")替换nil也会产生空的结果。

以下是示例代码和控制台结果:

代码语言:javascript
复制
let momentOptions = PHFetchOptions()
momentOptions.predicate = NSPredicate(format:"localizedTitle != nil")
momentList = PHAssetCollection.fetchMoments(with: nil)
let momentListFiltered = PHAssetCollection.fetchMoments(with: momentOptions)
let assetCount = momentList.count

for index in 0...assetCount-1 {
    let a = momentList[index]
    let sta = a.localizedTitle
    let stb = a.localizedLocationNames
    print(index, sta ?? "--", stb)
}

控制台上的结果:

代码语言:javascript
复制
0 -- []
1 -- []
2 Point Reyes National Seashore ["Point Reyes Station, CA"]
3 Þingeyjarsveit, Northeast Iceland ["Goðafossvegur"]
4 Djúpavogshreppur ["East Iceland"]
5 Rangárþing eystra ["South Iceland"]
6 New York - Washington Heights ["W 168th St"]
7 -- []
8 -- []
9 Jacksonville, NC ["Western Blvd"]
10 -- []
11 Locust Shade Park ["Triangle, VA"]
12 Piedmont Triad International Airport ["Friendship, NC"]

(lldb) po momentListFiltered
<PHFetchResult: 0x60c0002e2100> count=0

最后,为了确认正确的比较:

代码语言:javascript
复制
p momentList[7].localizedTitle == nil
(Bool) $R2 = true
EN

回答 1

Stack Overflow用户

发布于 2017-12-09 03:45:36

这似乎是Photos API中的一个错误或未记录的限制。我鼓励你通过Bug Reporter向苹果提交一个bug。

您可能会发现此替代方法很有用:

代码语言:javascript
复制
let momentLists = PHCollectionList.fetchMomentLists(with: .momentListCluster, options: nil)
if momentLists.count > 0 {
    for index in 0...momentLists.count - 1 {
        let a = momentLists[index]
        print(index, a.localizedTitle ?? "--", a.localizedLocationNames)
    }
} else {
    print("-- No moment lists! --")
}

这将获得一个moment集群列表,该列表似乎可以按地点和时间对照片进行分组。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47637654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档