Property

  • A read-only property that can be observed for its changes over time. There are three categories of read-only properties:

    Constant property

    Created by Property(value:), the producer and signal of a constant property would complete immediately when it is initialized.

    Existential property

    Created by Property(capturing:), it wraps any arbitrary PropertyProtocol types, and passes through the behavior. Note that it would retain the wrapped property.

    Existential property would be deprecated when generalized existential eventually lands in Swift.

    Composed property

    A composed property presents a composed view of its sources, which can be one or more properties, a producer, or a signal. It can be created using property composition operators, Property(_:) or Property(initial:then:).

    It does not own its lifetime, and its producer and signal are bound to the lifetime of its sources. It also does not have an influence on its sources, so retaining a composed property would not prevent its sources from deinitializing.

    Note that composed properties do not retain any of its sources.

    See more

    Declaration

    Swift

    public final class Property<Value> : PropertyProtocol
  • Represents a property that allows observation of its changes.

    Only classes can conform to this protocol, because having a signal for changes over time implies the origin must have a unique identity.

    See more

    Declaration

    Swift

    public protocol PropertyProtocol : AnyObject, BindingSource
  • A mutable property of type Value that allows observation of its changes.

    Instances of this class are thread-safe.

    See more

    Declaration

    Swift

    public final class MutableProperty<Value> : ComposableMutablePropertyProtocol
  • Represents an observable property that can be mutated directly.

    See more

    Declaration

    Swift

    public protocol MutablePropertyProtocol : BindingTargetProvider, PropertyProtocol where Self.Value == Self.Value
  • 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)`
    
    See more

    Declaration

    Swift

    public final class ValidatingProperty<Value, ValidationError> : MutablePropertyProtocol where ValidationError : Error