Fetch custom photo album using Swift

I had a project recently where I had to parse the photos inside a photo album at runtime. The code for this is surprisingly simple, but if you’ve never done it before it can be an interesting challenge in Swift.

When loading a custom photo album on iOS, we’re in fact fetching a PHAssetCollection that matches a given string. The given string when searching for an album is the album title as it appears in the Photos app. Use the following code to fetch the collection:

Say the app also needs to create the photo album, e.g. if the album does not exist. In order to do this, we can use the following code:

 

Leave a comment