> ## 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 Designated Initializer

A designated initializer is the primary initialization point for a class in Swift. It is responsible for fully initializing all uninitialized stored properties introduced by its own class before delegating the initialization process up the class hierarchy to its immediate superclass.

Every class must have at least one designated initializer, either explicitly defined or inherited. Unlike convenience initializers, designated initializers do not use any special modifier keywords.

```swift theme={"dark"}
init(parameters) {
    // 1. Initialize local stored properties
    // 2. Call super.init()
    // 3. Perform further configuration
}
```

## Core Mechanics and Delegation Rules

Swift enforces strict rules for class initialization to guarantee memory safety, known as **Two-Phase Initialization**. Designated initializers are the structural pillars of this process and must adhere to the following compiler-enforced rules:

1. **Upward Delegation:** A designated initializer must call a designated initializer from its immediate superclass. It cannot call a convenience initializer from its superclass, nor can it call another designated initializer within its own class.
2. **Exhaustive Local Initialization:** A designated initializer must assign a value to all stored properties introduced by its specific class *before* it delegates up to the superclass initializer.
3. **Phase 1 to Phase 2 Transition:** A designated initializer cannot assign a value to an inherited property until *after* it has called the superclass initializer. Calling `super.init()` completes Phase 1 (memory allocation and base initialization) and begins Phase 2 (customization).
4. **Method Resolution:** A designated initializer cannot call any instance methods, read the values of any instance properties, or refer to `self` as a value until Phase 1 is complete.

## Syntax and Execution Flow

The following example demonstrates the mechanical flow of a designated initializer adhering to Swift's strict delegation rules:

```swift theme={"dark"}
class Vehicle {
    var wheelCount: Int

    // Base Class Designated Initializer
    init(wheelCount: Int) {
        self.wheelCount = wheelCount
    }
}

class Bicycle: Vehicle {
    var hasBasket: Bool

    // Subclass Designated Initializer
    init(hasBasket: Bool) {
        // Step 1: Initialize properties introduced by Bicycle
        self.hasBasket = hasBasket
        
        // Step 2: Delegate to the immediate superclass designated initializer
        super.init(wheelCount: 2)
        
        // Step 3: Phase 2 customization (modifying inherited properties)
        self.wheelCount = 3 // e.g., modifying to a tricycle
    }
}
```

## The Funnel Principle

In Swift's initialization architecture, designated initializers act as funnel points. While a class may have multiple secondary `convenience` initializers, those convenience initializers must delegate *across* to another initializer within the same class, ultimately funneling down to a single designated initializer. Only the designated initializer is permitted to delegate *up* to the superclass, ensuring a predictable, linear path of memory allocation and property assignment.

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