Vapor Documentation Beta

Structure Extend

public struct Extend: Codable, ExpressibleByDictionaryLiteral

A wrapper around a simple [String: Any] storage dictionary used to implement Extendable.

final cass MyType: Extendable { ... }
extension MyType {
    var foo: Int {
        get { return extend.get(\MyType.foo, default: 0) }
        set { extend.set(\MyType.foo, to: newValue) }
    }
}
%3 Extend Extend Codable Codable Extend->Codable ExpressibleByDictionaryLiteral ExpressibleByDictionaryLiteral Extend->ExpressibleByDictionaryLiteral

Conforms To

Codable
ExpressibleByDictionaryLiteral

Initializers

init()

public init()

Create a new extend.

init(from:​)

public init(from decoder: Decoder) throws

See Codable.

init(dictionary​Literal:​)

public init(dictionaryLiteral elements: (String, Any))

See ExpressibleByDictionaryLiteral.

Properties

storage

var storage: [String: Any]

The internal storage.

Methods

encode(to:​)

public func encode(to encoder: Encoder) throws

See Codable.

get(_:​`default`:​)

public func get<T>(_ key: AnyKeyPath, `default` d: T) -> T

Gets a value from the Extend storage falling back to the default value if it does not exist or cannot be casted to T.

KeyPath-based alternative to get(_:default:).

let foo: Foo = extend.get(\MyType.Foo, default: defaultFoo)

set(_:​to:​)

public mutating func set<T>(_ key: AnyKeyPath, to newValue: T)

Set a value to the Extend storage.

KeyPath-based alternative to set(_:to:).

extend.set(\MyType.Foo, to: foo)

get(_:​`default`:​)

public func get<T>(_ key: String, `default` d: T) -> T

Gets a value from the Extend storage falling back to the default value if it does not exist or cannot be casted to T.

let foo: Foo = extend.get("foo", default: defaultFoo)

set(_:​to:​)

public mutating func set<T>(_ key: String, to newValue: T)

Set a value to the Extend storage.

extend.set("foo", to: foo)