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
T
to 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) -> ObservationToken
Parameters
observer
AnyObject that wants to observe an object that conforms to the protocol
identifier
Specify the identifier of the observer
eagerObserver
Observable type. When passed, the observer will get update on subscription
closure
A 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
observable
the observable object
self
.