Created
June 7, 2016 19:11
-
-
Save mavieth/f61a6ae8c63bec21d70de617f5b2e1b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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