Hanushka Suren
Hanushka Suren

Reputation: 793

Sort smart albums using Photos Framwork - IOS / SWIFT

In my application there is a view which lists all the available albums in users photo gallery. There, I'm getting albums without any issue. but the order of smart albums is different from the photo gallery. I want the order as in the original photo gallery.

This is how I get smart albums

let smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)

smartAlbums.enumerateObjects({ (collection, idx, stop) in

    if collection.assetCollectionSubtype != .smartAlbumVideos && collection.assetCollectionSubtype != .smartAlbumSlomoVideos{

        let photos = PHAsset.fetchAssets(in: collection, options: nil)

        if photos.count != 0{
            albumDetails.append([collection.localizedTitle!: photos.count])
        } 
    }
})

Here I avoid video albums and take photos count of each album. I want to avoid recently deleted album too(other than using 'localizedTitle').

Can anyone help me on these two? Any help would be highly appreciated.

Upvotes: 2

Views: 525

Answers (0)

Related Questions