Contents

Escapable

A type whose values can persist beyond their immediate local scope.

Declaration

protocol Escapable

Overview

Escapable values can be assigned to global or static variables, returned from functions, captured by escaping closures, and so on. All Swift types implicitly conform to this protocol by default, allowing them to be moved across scopes freely because they lack any lifetime dependencies.

In contrast, values of types that suppress their implicit conformance to Escapable (by writing ~Escapable) carry a lifetime dependency. These dependencies ensure the ~Escapable value does not live longer than the value it depends on. Explicit lifetime dependency annotations may be required when working with these types.

In generic contexts, ~Escapable works much in the same way as ~Copyable. It allows functions and types to work with values that may or may not be Escapable, and types can be conditionally Escapable based on their generic arguments. A conformance requirement for Escapable is automatically inferred in extensions and for generic type parameters, unless suppressed with ~Escapable.

See Also

Copying