Is it possible to fetch all PHAsset
s that don't belong to any PHAssetColletion
? Basically what I want to achieve is to get all photos that are not sorted to any album.
I know I can do this:
let photos = PHAsset.fetchAssets(with: PHFetchOptions())
var photosWithoutAlbum: [PHAsset] = []
photos.enumerateObjects({
asset, index, stop in
let albums = PHAssetCollection.fetchAssetCollectionsContaining(asset, with: .album, options: PHFetchOptions())
if albums.count == 0 {
photosWithoutAlbum.append(asset)
}
})
But maybe there is a better/faster way using PHFetchOptions
or different fetch method?