Skip to content

Instantly share code, notes, and snippets.

@mavieth
Created June 7, 2016 19:11
Show Gist options
  • Save mavieth/f61a6ae8c63bec21d70de617f5b2e1b8 to your computer and use it in GitHub Desktop.
Save mavieth/f61a6ae8c63bec21d70de617f5b2e1b8 to your computer and use it in GitHub Desktop.
let smartAlbums = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .AlbumRegular, options: nil) // Here you can specify Photostream, etc. as PHAssetCollectionSubtype.xxx
smartAlbums.enumerateObjectsUsingBlock( {
if let assetCollection = $0.0 as? PHAssetCollection {
print("album title: \(assetCollection.localizedTitle)")
// One thing to note with Smart Albums is that collection.estimatedAssetCount can return NSNotFound if estimatedAssetCount cannot be determined. As title suggest this is estimated. If you want to be sure of number of assets you have to perform fetch and get the count like:
let assetsFetchResult = PHAsset.fetchAssetsInAssetCollection(assetCollection, options: nil)
let numberOfAssets = assetsFetchResult.count
let estimatedCount = (assetCollection.estimatedAssetCount == NSNotFound) ? -1 : assetCollection.estimatedAssetCount
print("Assets count: \(numberOfAssets), estimate: \(estimatedCount)")
}
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment