1
iOS 11/Swift 4を使用して、写真ライブラリからモーメントのコレクションをフィルタリングしようとしています。私はちょうどPlaces
がほしいと思う。 nil
オプションを使用してモーメントのコレクションを取得すると、13の瞬間が得られ、8つの瞬間は非ゼロのタイトル(位置)を持ちます。私が単純な述語localizedTitle != nil
でフェッチのモーメントを行うと、結果は常にnilになります。空のString ("")
をnilに代入すると、空の結果も得られます。コンソール上のPHAssetCollectionのモーメントのフィルタリング
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)
}
結果::
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
最後に、ちょうど正しい比較確認する:
をp momentList[7].localizedTitle == nil
(Bool) $R2 = true
こんにちはDave!ご回答ありがとうございます。私はあなたが示唆するようにバグレポートを提出し、何かが来たら私たちは見るでしょう。私は、私の例のように、コレクションのリストを通常のコレクションよりも使用する利点は実際には感じません。それらはどちらも不変なので、テーブルビューを作成するために、私は乱雑でコレクションから配列を作成し、元のフィルタリングされていないコレクションに戻って、テーブルエントリがタップされたときにアセットを取得する必要があります。より良い方法が必要です! – BlueskyMed
私は、 'PHCollectionList'があなたの後ろにある場所を取得するかもしれないという利点があると思います。' PHAssetCollection'はフィルタリングすることができません。 :)アップルがあなたのバグを認めても、それが最初に修正されるのはiOS 12です。 –