ValidatingProperty
public final class ValidatingProperty<Value, ValidationError> : MutablePropertyProtocol where ValidationError : Error
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 current value of the property.
The value could have failed the validation. Refer to
resultfor the latest validation result.Declaration
Swift
public var value: Value { get set } -
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, Never> -
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, Never> -
The lifetime of the property.
Declaration
Swift
public let lifetime: Lifetime -
Create a
ValidatingPropertythat presents a mutable validating view for an inner mutable property.The proposed value is only committed when
validis returned by thevalidatorclosure.Note
inneris retained by the created property.Declaration
Swift
public init<Inner: ComposableMutablePropertyProtocol >( _ inner: Inner, _ validator: @escaping (Value) -> Decision ) where Inner.Value == ValueParameters
innerThe inner property which validated values are committed to.
validatorThe closure to invoke for any proposed value to
self. -
Create a
ValidatingPropertythat validates mutations before committing them.The proposed value is only committed when
validis returned by thevalidatorclosure.Declaration
Swift
public convenience init( _ initial: Value, _ validator: @escaping (Value) -> Decision )Parameters
initialThe initial value of the property. It is not required to pass the validation as specified by
validator.validatorThe closure to invoke for any proposed value to
self. -
Create a
ValidatingPropertythat presents a mutable validating view for an inner mutable property.The proposed value is only committed when
validis returned by thevalidatorclosure.Note
inneris retained by the created property.Declaration
Swift
public convenience init<Other: PropertyProtocol >( _ inner: MutableProperty <Value>, with other: Other, _ validator: @escaping (Value, Other.Value) -> Decision )Parameters
innerThe inner property which validated values are committed to.
otherThe property that
validatordepends on.validatorThe closure to invoke for any proposed value to
self. -
Create a
ValidatingPropertythat validates mutations before committing them.The proposed value is only committed when
validis returned by thevalidatorclosure.Declaration
Swift
public convenience init<Other: PropertyProtocol >( _ initial: Value, with other: Other, _ validator: @escaping (Value, Other.Value) -> Decision )Parameters
initialThe initial value of the property. It is not required to pass the validation as specified by
validator.otherThe property that
validatordepends on.validatorThe closure to invoke for any proposed value to
self. -
Create a
ValidatingPropertywhich validates mutations before committing them.The proposed value is only committed when
validis returned by thevalidatorclosure.Note
inneris retained by the created property.Declaration
Swift
public convenience init<U, E>( _ initial: Value, with other: ValidatingProperty<U, E>, _ validator: @escaping (Value, U) -> Decision )Parameters
initialThe initial value of the property. It is not required to pass the validation as specified by
validator.otherThe property that
validatordepends on.validatorThe closure to invoke for any proposed value to
self. -
Create a
ValidatingPropertythat presents a mutable validating view for an inner mutable property.The proposed value is only committed when
validis returned by thevalidatorclosure.Declaration
Swift
public convenience init<U, E>( _ inner: MutableProperty <Value>, with other: ValidatingProperty<U, E>, _ validator: @escaping (Value, U) -> Decision )Parameters
innerThe inner property which validated values are committed to.
otherThe property that
validatordepends on.validatorThe closure to invoke for any proposed value to
self. -
Represents a decision of a validator of a validating property made on a proposed value.
See moreDeclaration
Swift
public enum Decision -
Represents the result of the validation performed by a validating property.
See moreDeclaration
Swift
public enum Result