Enum as asset identifiers
By using extensions on UIImage, you can use an Enum to catalog specific image assets
We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
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.