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 result of the last attempted edit of the root property.

    Declaration

    Swift

    public let result: Property<Result>
  • 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 { 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, 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 the validator closure.

    Note

    inner is retained by the created property.

    Declaration

    Swift

    public init<Inner: ComposableMutablePropertyProtocol>(
    	_ inner: Inner,
    	_ validator: @escaping (Value) -> Decision
    ) 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 the validator closure.

    Declaration

    Swift

    public convenience init(
    	_ initial: Value,
    	_ validator: @escaping (Value) -> Decision
    )

    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 the validator 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) -> Decision
    )

    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 the validator closure.

    Declaration

    Swift

    public convenience init<Other: PropertyProtocol>(
    	_ initial: Value,
    	with other: Other,
    	_ validator: @escaping (Value, Other.Value) -> Decision
    )

    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 which validates mutations before committing them.

    The proposed value is only committed when valid is returned by the validator closure.

    Note

    inner is 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

    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 the validator closure.

    Declaration

    Swift

    public convenience init<U, E>(
    	_ inner: MutableProperty<Value>,
    	with other: ValidatingProperty<U, E>,
    	_ validator: @escaping (Value, U) -> Decision
    )

    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.

  • Represents a decision of a validator of a validating property made on a proposed value.

    See more

    Declaration

    Swift

    public enum Decision
  • Represents the result of the validation performed by a validating property.

    See more

    Declaration

    Swift

    public enum Result