Evaluates a closure while ensuring that the given instance is not destroyed before the closure returns.
SDK
- Xcode 7.0+
Framework
- Swift Standard Library
Declaration
func withExtendedLifetime<T, Result>(_ x: T, _ body: () throws -> Result) rethrows -> Result
Parameters
xAn instance to preserve until the execution of
bodyis completed.bodyA 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 thewithmethod.Extended Lifetime(_: _:)
Return Value
The return value, if any, of the body closure parameter.