> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift Type Alias

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.

```swift theme={"dark"}
typealias AliasName = ExistingType
```

## Technical Characteristics

**Type Equivalence**
Variables declared with a type alias can be directly assigned to variables of the underlying type without casting.

```swift theme={"dark"}
typealias Integer = Int

let aliasedValue: Integer = 42
let standardValue: Int = aliasedValue // Compiles without type conversion
```

**Closure Signatures**
Type aliases can encapsulate complex closure signatures, including parameters and return types.

```swift theme={"dark"}
import Foundation

typealias CompletionHandler = (Data?, URLResponse?, Error?) -> Void

// The alias can now be used as a type annotation
var onComplete: CompletionHandler?
```

**Generic Type Aliases**
Type aliases support generic parameters. This allows you to partially or fully apply type arguments to an existing generic type.

```swift theme={"dark"}
// Partially applied generic type
typealias StringDictionary<Value> = Dictionary<String, Value>

let metadata: StringDictionary<Int> = ["count": 10]
```

**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`).

```swift theme={"dark"}
typealias HashableAndComparable = Hashable & Comparable

struct CustomKey: HashableAndComparable {
    let id: Int
    
    // Swift synthesizes Hashable and Equatable requirements for the 'id' property.
    // Comparable requires an explicit implementation of the '<' operator.
    static func < (lhs: CustomKey, rhs: CustomKey) -> Bool {
        return lhs.id < rhs.id
    }
}
```

**Tuple Aliasing**
Type aliases can define named tuples, preserving the element labels of the underlying tuple structure.

```swift theme={"dark"}
typealias Coordinates = (x: Double, y: Double, z: Double)

let origin: Coordinates = (x: 0.0, y: 0.0, z: 0.0)
```

## 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.

```swift theme={"dark"}
internal struct InternalType {}
public struct PublicType {}

// Compiler Error: Type alias cannot be declared public because its underlying type is internal
public typealias PublicAlias = InternalType 

// Valid: Type alias has a lower or equal access level compared to its underlying type
private typealias PrivateAlias = PublicType 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Swift Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
