ObservableProperty
public class ObservableProperty<ValueType>
A basic implementation of a property whose value
can be observed
using callbacks.
Example:
var property = ObservableProperty(1)
property.subscribe { newValue in
print("newValue: \(newValue)")
}
property.value = 2
// Executing the above code prints:
// "newValue: 2"
-
The type of the callback to be called when the
value
changes.Declaration
Swift
public typealias CallbackType = (ValueType -> ())
-
The
value
stored in this instance. Setting it to a new value will notify any subscriptions registered through thesubscribe
method.Declaration
Swift
public var value: ValueType
-
Declaration
Swift
public init(_ value: ValueType)
Parameters
value
The initial value to store.
-
Register a subscriber that will be called with the new value when the
value
changes.Declaration
Swift
public func subscribe(callback: CallbackType)
Parameters
callback
The function to call when the value changes.