Property
public final class Property<Value> : PropertyProtocol
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.
-
The current value of the property.
Declaration
Swift
public var value: Value { get }
-
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 or has no further changes.
Note
Ifself
is a composed property, the producer would be bound to the lifetime of its sources.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 or has no further changes.
Note
Ifself
is a composed property, the signal would be bound to the lifetime of its sources.Declaration
Swift
public let signal: Signal<Value, Never>
-
Initializes a constant property.
Declaration
Swift
public init(value: Value)
Parameters
property
A value of the constant property.
-
Initializes an existential property which wraps the given property.
Note
The resulting property retains the given property.
Declaration
Swift
public init<P>(capturing property: P) where Value == P.Value, P : PropertyProtocol
Parameters
property
A property to be wrapped.
-
Initializes a composed property which reflects the given property.
Note
The resulting property does not retain the given property.
Declaration
Swift
public convenience init<P>(_ property: P) where Value == P.Value, P : PropertyProtocol
Parameters
property
A property to be wrapped.
-
Initializes a composed property that first takes on
initial
, then each value sent on a signal created byproducer
.Declaration
Swift
public convenience init(initial: Value, then values: SignalProducer<Value, Never>)
Parameters
initial
Starting value for the property.
values
A producer that will start immediately and send values to the property.
-
Initializes a composed property that first takes on
initial
, then each value sent on a signal created byproducer
.Declaration
Swift
public convenience init<Values>(initial: Value, then values: Values) where Value == Values.Value, Values : SignalProducerConvertible, Values.Error == Never
Parameters
initial
Starting value for the property.
values
A producer that will start immediately and send values to the property.
-
Initializes a composed property that first takes on
initial
, then each value sent on a signal created byproducer
.Declaration
Swift
public convenience init(initial: Value, then values: SignalProducer<Value.Wrapped, Never>)
Parameters
initial
Starting value for the property.
values
A producer that will start immediately and send values to the property.
-
Initializes a composed property that first takes on
initial
, then each value sent on a signal created byproducer
.Declaration
Swift
public convenience init<Values>(initial: Value, then values: Values) where Values : SignalProducerConvertible, Value.Wrapped == Values.Value, Values.Error == Never
Parameters
initial
Starting value for the property.
values
A producer that will start immediately and send values to the property.