Skip to main content
A type alias in Swift provides an alternative name for an existing type. It does not define a new, distinct type in the compiler’s type system; rather, it acts as a named reference to an underlying type. Because the alias and the original type are strictly interchangeable, the compiler evaluates them as identical during type checking.

Syntax

A type alias is declared using the typealias keyword, followed by the new identifier, the assignment operator (=), and the existing type.

Technical Characteristics

Type Equivalence Variables declared with a type alias can be directly assigned to variables of the underlying type without casting.
Closure Signatures Type aliases can encapsulate complex closure signatures, including parameters and return types.
Generic Type Aliases Type aliases support generic parameters. This allows you to partially or fully apply type arguments to an existing generic type.
Protocol Composition A type alias can represent a composition of multiple protocols using the & operator. The Swift standard library uses this mechanic internally (e.g., Codable).
Tuple Aliasing Type aliases can define named tuples, preserving the element labels of the underlying tuple structure.

Access Control

Type aliases adhere to standard Swift access control modifiers (public, internal, fileprivate, private). A type alias cannot have a higher access level than the type it aliases. For example, a public type alias cannot reference an internal or private type.
Tired of Poor Swift Skills? Fix That With Deep Grasping!Learn More