SwiftKit Documentation

Structure Default​Value

@propertyWrapper
public struct DefaultValue<T>  

Property wrapper to set default value if spesific condition is fulfilled

example

struct User {
    @DefaultValue(if: { $0.isEmpty }, then: "admin", initialValue: "")
    var password: String
}

if everytime password is set, and empty, then we use "admin" as default value

%23 DefaultValue DefaultValue Equatable Equatable DefaultValue->Equatable Hashable Hashable DefaultValue->Hashable

Conforms To

Equatable
Hashable

Nested Type Aliases

Condition

public typealias Condition = (T) -> Bool

Initializers

init(if:​then:​initial​Value:​)

public init(if condition: @escaping Condition, then defaultValue: T, initialValue: T)  

Properties

condition

public let condition: Condition

default​Value

public let defaultValue: T

wrapped​Value

public var wrappedValue: T  

Methods

validate(condition:​then:​else:​)

public static func validate(
        condition: @escaping Condition,
        then defaultValue: @autoclosure () throws -> T,
        else newValue: @autoclosure () throws -> T
    ) rethrows -> T