Enum as asset identifiers

swift, xcode, enum – Oct 05 2018

By using extensions on UIImage, you can use an Enum to catalog specific image assets

• • •

In a project you can create a separate file called UIImage+Assets.swift write out an extension on swift±UIImage class and reference brand assets with an swift±enum.

extension UIImage {

    enum BrandAssetIdentifier: String {
        case Logo = "company_logo.jpg"
        case LogoFooter = "company_logo.jpg"
        case Avatar = "avatar.jpg"

    convenience init!(brandAssetIdentifier: BrandAssetIdentifier) {
        self.init(named: brandAssetIdentifier.rawValue)


let logo = UIImage(brandAssetIdentifier: .Logo)

Excellent tip for organizing common assets. This example is modified from a presentation done in WWDC 2015 - Swift in Practice.

Follow on Twitter
Follow on Github