MutableProperty

public final class MutableProperty<Value> : ComposableMutablePropertyProtocol

A mutable property of type Value that allows observation of its changes.

Instances of this class are thread-safe.

  • The current value of the property.

    Setting this to a new value will notify all observers of signal, or signals created using producer.

    Declaration

    Swift

    public var value: Value { get set }
  • The lifetime of the property.

    Declaration

    Swift

    public let lifetime: Lifetime
  • 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>
  • 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 var producer: SignalProducer<Value, NoError> { get }
  • Initializes a mutable property that first takes on initialValue

    Declaration

    Swift

    public init(_ initialValue: Value)

    Parameters

    initialValue

    Starting value for the mutable property.

  • Atomically replaces the contents of the variable.

    Declaration

    Swift

    @discardableResult
    public func swap(_ newValue: Value) -> Value

    Parameters

    newValue

    New property value.

    Return Value

    The previous property value.

  • Atomically modifies the variable.

    Declaration

    Swift

    @discardableResult
    public func modify<Result>(_ action: (inout Value) throws -> Result) rethrows -> Result

    Parameters

    action

    A closure that accepts an inout reference to the value.

    Return Value

    The result of the action.

  • Atomically performs an arbitrary action using the current value of the variable.

    Declaration

    Swift

    @discardableResult
    public func withValue<Result>(_ action: (Value) throws -> Result) rethrows -> Result

    Parameters

    action

    A closure that accepts current property value.

    Return Value

    the result of the action.