Swift Skill Architecture
1. Skill Context
Focus: iOS, macOS, watchOS development, Protocol-Oriented Programming (POP), safe memory management (ARC).
Triggers: swift, ios, xcode, protocol-oriented, arc, SwiftUI, UIKit.
2. Core Principles
- Protocol-Oriented Programming (POP): Swift prefers protocols and protocol extensions over deep class inheritance. This avoids the fragile base class problem and favors composition.
- Value Types over Reference Types: Structs and Enums are value types (allocated on the stack, copied on assignment). Swift heavily encourages using structs for state management to avoid unintended side effects.
- Automatic Reference Counting (ARC): Swift does not have a Garbage Collector. It counts references at compile/runtime. Developers must explicitly manage strong reference cycles using
weak and unowned references.
3. Anti-Patterns
- Force Unwrapping (
!): Crashing the app because an optional is suddenly nil. Always use if let or guard let.
- Massive View Controller (MVC): Putting all network, UI, and business logic inside a
UIViewController. Use MVVM, VIPER, or TCA (The Composable Architecture) instead.
- Retain Cycles in Closures: Forgetting
[weak self] in an escaping closure (like a network request callback), causing memory leaks because the closure captures the class instance strongly.
4. References
references/swift-fundamentals.md — Optionals, Value Types, Closures.
references/swift-advanced.md — Actors, Property Wrappers, Result Builders.
references/swift-testing.md — XCTest and UI Testing.
1---2name: swift3description: Swift Skill Architecture4---5# Swift Skill Architecture67## 1. Skill Context8**Focus**: iOS, macOS, watchOS development, Protocol-Oriented Programming (POP), safe memory management (ARC).9**Triggers**: swift, ios, xcode, protocol-oriented, arc, SwiftUI, UIKit.1011## 2. Core Principles12- **Protocol-Oriented Programming (POP)**: Swift prefers protocols and protocol extensions over deep class inheritance. This avoids the fragile base class problem and favors composition.13- **Value Types over Reference Types**: Structs and Enums are value types (allocated on the stack, copied on assignment). Swift heavily encourages using structs for state management to avoid unintended side effects.14- **Automatic Reference Counting (ARC)**: Swift does not have a Garbage Collector. It counts references at compile/runtime. Developers must explicitly manage strong reference cycles using `weak` and `unowned` references.1516## 3. Anti-Patterns17- **Force Unwrapping (`!`)**: Crashing the app because an optional is suddenly `nil`. Always use `if let` or `guard let`.18- **Massive View Controller (MVC)**: Putting all network, UI, and business logic inside a `UIViewController`. Use MVVM, VIPER, or TCA (The Composable Architecture) instead.19- **Retain Cycles in Closures**: Forgetting `[weak self]` in an escaping closure (like a network request callback), causing memory leaks because the closure captures the class instance strongly.2021## 4. References22- `references/swift-fundamentals.md` — Optionals, Value Types, Closures.23- `references/swift-advanced.md` — Actors, Property Wrappers, Result Builders.24- `references/swift-testing.md` — XCTest and UI Testing.