ImageAsset

public protocol ImageAsset : RawRepresentable where Self.RawValue == String

Any named image asset can be loaded from an asset catalog.

All properties and functions have default implementations. At a minimum just have your string-based enum conform to ImageAsset (and have an asset catalog with matching assets). If your enum and assets live inside a Swift package, override bundle to return .module. If your assets are categorized within their asset catalog by a namespace, then override namespace to return the proper string prefix.

  • bundle Default implementation

    The bundle containing the image assets for this enum (default is .main)

    Default Implementation

    The bundle containing the image assets for this enum (default is .main)

    Declaration

    Swift

    static var bundle: Bundle { get }
  • namespace Default implementation

    Optional namespace for the image assets (default is nil).

    Default Implementation

    Optional namespace for the image assets (default is nil)

    Declaration

    Swift

    static var namespace: String? { get }
  • fallbackImage Default implementation

    Fallback image to use in case an image asset cannot be loaded. (default is a 16 x 16 square filled with .systemPink)

    Default Implementation

    Fallback image to use in case an image asset cannot be loaded. (default is a 16 x 16 square filled with .systemPink)

    Declaration

    Swift

    static var fallbackImage: UIImage { get }
  • image Default implementation

    An image asset for this name value.

    Default implementation calls loadImage and nil-coalesces to fallbackImage.

    Default Implementation

    An image asset for this name value.

    Default implementation calls loadImage and nil-coalesces to fallbackImage.

    Declaration

    Swift

    var image: UIImage { get }
  • loadImage() Default implementation

    Loads the image.

    Default Implementation

    Loads the named image.

    Default implementation uses UIImage(named:in:compatibleWith:) passing in the associated namespace (prepended to rawValue) and bundle.

    Declaration

    Swift

    func loadImage() -> UIImage?

    Return Value

    The named image or else nil if the named asset cannot be loaded.