Colorable

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

Any named color asset that can be loaded from an asset catalog (primarily for use with string-based enums).

All properties and functions have default implementations. At a minimum just have your string-based enum conform to Colorable (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 color assets for this enum (default is .main)

    Default Implementation

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

    Declaration

    Swift

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

    Optional namespace for the color assets (default is nil)

    Default Implementation

    Optional namespace for the color assets (default is nil)

    Declaration

    Swift

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

    Fallback color to use in case a color asset cannot be loaded (default is .systemPink)

    Default Implementation

    Fallback color to use in case a color asset cannot be loaded (default is .systemPink)

    Declaration

    Swift

    static var fallbackColor: UIColor { get }
  • loadColor() Default implementation

    Loads the named color.

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

    Default Implementation

    Loads the named color.

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

    Declaration

    Swift

    func loadColor() -> UIColor?

    Return Value

    The named color or else nil if the named asset cannot be loaded

  • color Default implementation

    A color asset for this name value.

    Default implementation calls loadColor and nil-coalesces to fallbackColor.

    Default Implementation

    A color asset for this name value.

    Default implementation calls loadColor and nil-coalesces to fallbackColor.

    Declaration

    Swift

    var color: UIColor { get }