Structure
DefaultValue
@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
Relationships
Conforms To
Equatable
Hashable
Nested Type Aliases
Condition
public typealias Condition = (T) -> Bool
Initializers
init(if:then:initialValue:)
public init(if condition: @escaping Condition, then defaultValue: T, initialValue: T)
Properties
condition
public let condition: Condition
defaultValue
public let defaultValue: T
wrappedValue
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