Allows a nonescaping closure to temporarily be used as if it were allowed to escape.
A non-escaping closure value that will be made escapable for the duration of the execution of the do block.
A code block that will be immediately executed, receiving an escapable copy of closure as an argument.
the forwarded return value from the do block.
This is useful when you need to pass a closure to an API that can’t statically guarantee the closure won’t escape when used in a way that won’t allow it to escape in practice, such as in a lazy collection view:
or with async:
withoutActuallyEscaping provides a temporarily-escapable copy of the closure that can be used in these situations:
It is undefined behavior for the escapable closure to be stored, referenced, or executed after withoutActuallyEscaping returns. A future version of Swift will introduce a dynamic check to trap if the escapable closure is still referenced at the point withoutActuallyEscaping returns.