Key

public enum Key<T>: CustomStringConvertible

Mechanica

Base enum for static keys with a phantom type. Specialize this enum with a type and initialize it with a key, key path (both namespaced or not).

Note

Use Key to avoid stringly typed APIs.

  • simple: a String key or key path.

  • namespaced: a namespaced String key or key path.

  • Example:

    Key<String>("myKey1") // value: myKey1
    Key<Int>("myKey2", namespace: "org.tinrobots")  // value: org.tinrobots.myKey2
    Key<Bool>("myKey3", namespace: "org.tinrobots") // value: org.tinrobots.myKey3
    Key<Double>("myKey4", namespace: "org", "tinrobots") // value: org.tinrobots.myKey4
    
    • Mechanica

      A simple String key, use it for no namespaced keys or key paths.

      Declaration

      Swift

      case simple(String)
    • Mechanica

      A namespaced String key.

      Declaration

      Swift

      case namespaced(String, namespace: String)
    • Create a new Key.

      Declaration

      Swift

      public init(_ string: String, namespace: String...)

      Parameters

      string

      key or key path value.

      namespace

      optional namespace for the key to avoid collision with other keys with the same value defined in other libraries.

    • Mechanica

      Returns the key formatted with the namespace if defined.

      Declaration

      Swift

      public var value: String
    • Declaration

      Swift

      public var description: String