AnyEnum

struct AnyEnum
extension AnyEnum : AutomationValue, Enum, Equatable, Hashable, RawRepresentable, Sendable

A type-erased Enum

  • Undocumented

    Declaration

    Swift

    typealias OriginalValue = UInt64
  • Creates a new instance wrapping the given object.

    Declaration

    Swift

    init<T>(erasing object: T) where T : Enum
  • Undocumented

    Declaration

    Swift

    func cast<T>(_ type: T.Type = T.self) -> T? where T : Enum
  • Undocumented

    Declaration

    Swift

    func `is`<T>(_ type: T.Type = T.self) -> Bool where T : Enum
  • Creates a new instance with the specified raw value.

    If there is no value of the type that corresponds with the specified raw value, this initializer returns nil. For example:

    enum PaperSize: String {
        case A4, A5, Letter, Legal
    }
    
    print(PaperSize(rawValue: "Legal"))
    // Prints "Optional("PaperSize.Legal")"
    
    print(PaperSize(rawValue: "Tabloid"))
    // Prints "nil"
    

    Declaration

    Swift

    init(rawValue: UInt64)

    Parameters

    rawValue

    The raw value to use for the new instance.

  • The corresponding value of the raw type.

    A new instance initialized with rawValue will be equivalent to this instance. For example:

    enum PaperSize: String {
        case A4, A5, Letter, Legal
    }
    
    let selectedSize = PaperSize.Letter
    print(selectedSize.rawValue)
    // Prints "Letter"
    
    print(selectedSize == PaperSize(rawValue: selectedSize.rawValue)!)
    // Prints "true"
    

    Declaration

    Swift

    var rawValue: UInt64 { get }
  • Undocumented

    Declaration

    Swift

    static func unrecognizedCase() -> AnyEnum
  • Returns a Boolean value indicating whether two values are equal.

    Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

    Declaration

    Swift

    static func == (lhs: AnyEnum, rhs: AnyEnum) -> Bool

    Parameters

    lhs

    A value to compare.

    rhs

    Another value to compare.

  • Hashes the essential components of this value by feeding them into the given hasher.

    Implement this method to conform to the Hashable protocol. The components used for hashing must be the same as the components compared in your type’s == operator implementation. Call hasher.combine(_:) with each of these components.

    Important

    In your implementation of hash(into:), don’t call finalize() on the hasher instance provided, or replace it with a different instance. Doing so may become a compile-time error in the future.

    Declaration

    Swift

    func hash(into hasher: inout Hasher)