ValidatingProperty
public final class ValidatingProperty<Value, ValidationError: Swift.Error>: MutablePropertyProtocol
A mutable property that validates mutations before committing them.
If the property wraps an arbitrary mutable property, changes originated from the inner property are monitored, and would be automatically validated. Note that these would still appear as committed values even if they fail the validation.
let root = MutableProperty("Valid")
let outer = ValidatingProperty(root) {
$0 == "Valid" ? .valid : .invalid(.outerInvalid)
}
outer.result.value // `.valid("Valid")
root.value = "🎃"
outer.result.value // `.invalid("🎃", .outerInvalid)`
-
The result of the last attempted edit of the root property.
Declaration
Swift
public let result: Property<ValidationResult<Value, ValidationError>>
-
The current value of the property.
The value could have failed the validation. Refer to
result
for the latest validation result.Declaration
Swift
public var value: Value
-
A producer for Signals that will send the property’s current value, followed by all changes over time, then complete when the property has deinitialized.
Declaration
Swift
public let producer: SignalProducer<Value, NoError>
-
A signal that will send the property’s changes over time, then complete when the property has deinitialized.
Declaration
Swift
public let signal: Signal<Value, NoError>
-
The lifetime of the property.
Declaration
Swift
public let lifetime: Lifetime
-
Create a
ValidatingProperty
that presents a mutable validating view for an inner mutable property.The proposed value is only committed when
valid
is returned by thevalidator
closure.Note
inner
is retained by the created property.Declaration
Swift
public init<Inner: ComposableMutablePropertyProtocol>( _ inner: Inner, _ validator: @escaping (Value) -> ValidatorOutput<Value, ValidationError> ) where Inner.Value == Value
Parameters
inner
The inner property which validated values are committed to.
validator
The closure to invoke for any proposed value to
self
. -
Create a
ValidatingProperty
that validates mutations before committing them.The proposed value is only committed when
valid
is returned by thevalidator
closure.Declaration
Swift
public convenience init( _ initial: Value, _ validator: @escaping (Value) -> ValidatorOutput<Value, ValidationError> )
Parameters
initial
The initial value of the property. It is not required to pass the validation as specified by
validator
.validator
The closure to invoke for any proposed value to
self
. -
Create a
ValidatingProperty
that presents a mutable validating view for an inner mutable property.The proposed value is only committed when
valid
is returned by thevalidator
closure.Note
inner
is retained by the created property.Declaration
Swift
public convenience init<Other: PropertyProtocol>( _ inner: MutableProperty<Value>, with other: Other, _ validator: @escaping (Value, Other.Value) -> ValidatorOutput<Value, ValidationError> )
Parameters
inner
The inner property which validated values are committed to.
other
The property that
validator
depends on.validator
The closure to invoke for any proposed value to
self
. -
Create a
ValidatingProperty
that validates mutations before committing them.The proposed value is only committed when
valid
is returned by thevalidator
closure.Declaration
Swift
public convenience init<Other: PropertyProtocol>( _ initial: Value, with other: Other, _ validator: @escaping (Value, Other.Value) -> ValidatorOutput<Value, ValidationError> )
Parameters
initial
The initial value of the property. It is not required to pass the validation as specified by
validator
.other
The property that
validator
depends on.validator
The closure to invoke for any proposed value to
self
. -
Create a
ValidatingProperty
that presents a mutable validating view for an inner mutable property.The proposed value is only committed when
valid
is returned by thevalidator
closure.Note
inner
is retained by the created property.Declaration
Swift
public convenience init<U, E: Swift.Error>( _ inner: MutableProperty<Value>, with other: ValidatingProperty<U, E>, _ validator: @escaping (Value, U) -> ValidatorOutput<Value, ValidationError> )
Parameters
inner
The inner property which validated values are committed to.
other
The property that
validator
depends on.validator
The closure to invoke for any proposed value to
self
. -
Create a
ValidatingProperty
that validates mutations before committing them.The proposed value is only committed when
valid
is returned by thevalidator
closure.Declaration
Swift
public convenience init<U, E: Swift.Error>( _ initial: Value, with other: ValidatingProperty<U, E>, _ validator: @escaping (Value, U) -> ValidatorOutput<Value, ValidationError> )
Parameters
initial
The initial value of the property. It is not required to pass the validation as specified by
validator
.other
The property that
validator
depends on.validator
The closure to invoke for any proposed value to
self
.