withExtendedLifetime(_:_:)
Evaluates a closure while ensuring that the given instance is not destroyed before the closure returns.
Declaration
func withExtendedLifetime<T, E, Result>(_ x: borrowing T, _ body: () throws(E) -> Result) throws(E) -> Result where E : Error, T : ~Copyable, T : ~Escapable, Result : ~CopyableParameters
- x:
An instance to preserve until the execution of
bodyis completed. - body:
A closure to execute that depends on the lifetime of
xbeing extended. Ifbodyhas a return value, that value is also used as the return value for thewithExtendedLifetime(_:_:)method.
Return Value
The return value, if any, of the body closure parameter.