Lifetime
public final class Lifetime
Represents the lifetime of an object, and provides a hook to observe when the object deinitializes.
-
A signal that sends a
completedevent when the lifetime ends.Note
Consider usingLifetime.observeEndedif only a closure observer is to be attached.Declaration
Swift
public var ended: Signal<Never, Never> { get } -
A flag indicating whether the lifetime has ended.
Declaration
Swift
public var hasEnded: Bool { get } -
Initialize a
Lifetimefrom 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
tokenA lifetime token for detecting the deinitialization of the associated object.
-
Observe the termination of
self.Declaration
Swift
@discardableResult public func observeEnded(_ action: @escaping () -> Void) -> Disposable?Parameters
actionThe action to be invoked when
selfends.Return Value
A disposable that detaches
actionfrom the lifetime, orniliflifetimehas already ended. -
Add the given disposable as an observer of
self.Declaration
Swift
@discardableResult public static func += (lifetime: Lifetime, disposable: Disposable?) -> Disposable?Parameters
disposableThe disposable to be disposed of when
selfends.Return Value
A disposable that detaches
disposablefrom the lifetime, orniliflifetimehas already ended. -
A
Lifetimethat has already ended.Declaration
Swift
public static let empty: Lifetime -
A token object which completes its associated
Lifetimewhen it deinitializes, or whendispose()is called.It is generally used in conjuncion with
Lifetimeas a private deinitialization trigger.class MyController { private let (lifetime, token) = Lifetime.make() }Declaration
Swift
public final class Token
View on GitHub
Install in Dash
Lifetime Class Reference