Lifetime
public final class Lifetime
Represents the lifetime of an object, and provides a hook to observe when the object deinitializes.
-
A
Lifetime
that has already ended.Declaration
Swift
public static var empty: Lifetime
-
A signal that sends a
completed
event when the lifetime ends.Note
Consider usingLifetime.observeEnded
if only a closure observer is to be attached.Declaration
Swift
public let ended: Signal<(), NoError>
-
Initialize a
Lifetime
from a lifetime token, which is expected to be associated with an object.Important
The resulting lifetime object does not retain the lifetime token.
Declaration
Swift
public convenience init(_ token: Token)
Parameters
token
A lifetime token for detecting the deinitialization of the associated object.
-
Observe the termination of
self
.Declaration
Swift
public func observeEnded(_ action: @escaping () -> Void) -> Disposable?
Parameters
action
The action to be invoked when
self
ends.Return Value
A disposable that detaches
action
from the lifetime, ornil
iflifetime
has already ended. -
A token object which completes its signal when it deinitializes.
It is generally used in conjuncion with
Lifetime
as a private deinitialization trigger.class MyController { private let (lifetime, token) = Lifetime.make() }
Declaration
Swift
public final class Token