ObservableHandler
public final class ObservableHandler : Observable
A thread-safe implementation of the Observable
container.
Any method can be called from any queue. The notification of observers, completions, and other closures will be executed on a dispatch queue provided in the init method.
Note
If you rely on the onLastObserverRemoved closure, callremoveObserver(:)
explicitly.
If the observer is destroyed without an explicit call to removeObserver(:)
, the onLastObserverRemoved
call will be delayed
until the next notify event when we detect that the last observer is nil
and remove it.
Add an Observer
for Observable
object.
Declaration
Swift
public func addObserver(_ observer: Observer)
Parameters
observer
|
|
Create an ObservableHandler
instance.
Declaration
Swift
public init(
dispatchQueue: DispatchQueue = .main,
onFirstObserverAdded: (() -> ())? = nil,
onLastObserverRemoved: (() -> ())? = nil
)
Notify observers about some specific event.
Declaration
Swift
public func notifyObservers(notificationAction: @escaping (Observer) -> ())
Parameters
notificationAction
|
Use the closure to define what event every observer will receive.
This method will apply the |
Notify observers about some specific event.
Declaration
Swift
public func notifyObservers(notificationAction: @escaping (Observer) -> (), completion: (() -> ())?)
Parameters
notificationAction
|
Use the closure to define what event every observer will receive.
This method will apply the |
completion
|
Called when the |
Remove an Observer
from Observable
object.
Declaration
Swift
public func removeObserver(_ observer: Observer)
Parameters
observer
|
|