Evaluates a closure while ensuring that the given instance is not destroyed before the closure returns.
Parameters:
x: An instance to preserve until the execution of body
is completed.
body: A closure to execute that depends on the lifetime of x
being
extended. If body
has a return value, that value is also used as the
return value for the withExtendedLifetime(_:_:)
method.
Returns: The return value, if any, of the body
closure parameter.
Declaration
func
withExtendedLifetime
<
T
,
Result
>
(
_
x
:
T
,
_
body
: (
T
)
throws
-
>
Result
)
rethrows
-
>
Result
Evaluates a closure while ensuring that the given instance is not destroyed before the closure returns.
Parameters: x: An instance to preserve until the execution of
body
is completed. body: A closure to execute that depends on the lifetime ofx
being extended. Ifbody
has a return value, that value is also used as the return value for thewithExtendedLifetime(_:_:)
method. Returns: The return value, if any, of thebody
closure parameter.Declaration
func
withExtendedLifetime
<
T
,
Result
>
(
_
x
:
T
,
_
body
: ()
throws
-
>
Result
)
rethrows
-
>
Result