What is the best way to display the latest 10 images from an album?

This is what I am doing. A user chooses what album they want to use and the number of images they want to use from the album. For example 15 images. When a user navigates to a certain controller view it will display the first image and then they click next it will display the next image… until they reach 15.

I am using the PhotoHelper library for getting the images.

var userAlbumArray: [PhotoAlbum] = []
var options = PhotosHelper.defaultImageFetchOptions
options.deliveryMode = .FastFormat

var fetchOptions = PhotosHelper.FetchOptions()
fetchOptions.count = 15

PhotosHelper.getImagesFromAlbum("Album Name", options: options, fetchOptions: fetchOptions, completion: { result in
    switch result {
    // When options.synchronous is set to true an array of all assets is fetched.
    case .Assets(let images):
    // when options.synchronous is set to false the system fetches one asset at a time calling this completion handler multiple times
    case .Asset(let image):
        let alb = PhotoAlbum(title: album.localizedTitle ?? "", thumbnail: image)
    case .Error:

import Foundation
import UIKit

struct PhotoAlbum {

    var title: String
    var thumbnail: UIImage?

    init(title: String, thumbnail: UIImage?) {
        self.title = title
        self.thumbnail = thumbnail

Since the images get loaded asynchronously my idea was to create a PhotoAlbum object for each image and add it to an array on App initial load. Then save the array to UserDefaults once the user got the View Controller it will get the images from UserDefaults.

I tried saving it to UserDefault but I was not able to. It might be because of the UIImage.

Am I approaching this correctly or does anyone have a better suggestion?

@albertski Thanks very much for your question!

I personally found that using the Kingfisher library was quite helpful, and easy to use. With respect to storing images to UserDefaults, this is typically done when you want to persist data after the app has been shut down. Is this your goal?


I ended up just getting the PHAsset and storing the local identifier in the array.

This topic was automatically closed after 166 days. New replies are no longer allowed.