Observable
public protocol Observable : AnyObject
Protocol that allows an object to be observed by other objects.
When conforming to this protocol, make sure to invoke the notifyObservers method
once the conforming object has been updated.
-
The list of identifiers linked to objects watching this observable
Declaration
Swift
var onUpdate: ([ObservableIdentifier : (Observable) -> Void]) { get set } -
addObserver(_:Default implementationidentifier: eagerObserver: onRemove: _: ) Allows an object
Tto observe changes made to an object that conforms to the protocolDefault Implementation
Declaration
Swift
func addObserver<T: AnyObject>(_ observer: T, identifier: ObservableIdentifier, eagerObserver: Observable?, onRemove: ((ObservableIdentifier) -> Void)?, _ closure: @escaping (T?, ObservableIdentifier, Observable) -> Void) -> ObservationTokenParameters
observerAnyObject that wants to observe an object that conforms to the protocol
identifierSpecify the identifier of the observer
eagerObserverObservable type. When passed, the observer will get update on subscription
closureA closure that passes through the object under observation, and the object observing it.
Return Value
A token that can be used to cancel the observation
-
notifyObservers(_:Default implementation) This should be called once the observable has changed/updated
Default Implementation
Declaration
Swift
func notifyObservers(_ observable: Observable)Parameters
observablethe observable object
self.
Install in Dash
Observable Protocol Reference