api: YAML JSON TOON Database
version: 1.0.0
format: yaml
dataset:
  id: 2909
  slug: swift-language-features
  title: Swift Language Features
  description: "Swift programming language features: optionals, protocol-oriented programming, generics, async/await, SwiftUI, and memory management (ARC)."
  summary: "Swift language features with the version they arrived, a description, syntax and notes: optionals, protocol-oriented programming, generics, result builders, async/await, actors, property wrappers and automatic reference counting."
  use_when:
    - You are learning Swift or reading SwiftUI-era code.
    - You need the Swift version in which a feature appeared.
  caveats:
    - Swift evolves quickly; confirm feature availability against the Xcode and Swift version you target.
    - Strict concurrency checking has been rolled out in stages and can change build behavior.
  related:
    - language-comparison-2026
    - csharp-dotnet-features
    - rust-language-features
    - behavioral-design-patterns
  entry_count: 8
  fields:
    - section: features
      field: name
      type: string
      example: Optionals
    - section: features
      field: introduced
      type: string
      example: Swift 1.0
    - section: features
      field: description
      type: string
      example: "Type-safe way to represent nil values: Optional…"
    - section: features
      field: syntax
      type: string
      example: "var name: String?; if let unwrapped = name { }"
    - section: features
      field: notes
      type: string
      example: Force unwrap (!) crashes on nil; use guard let …
  category: Programming Languages
  category_slug: programming-languages
  tags: swift,ios,optionals,protocols,generics,async-await,swiftui,arc
  view_count: 40
  created_at: 1778695229
  updated_at: 1778695229
data:
  features:
    - name: Optionals
      introduced: Swift 1.0
      description: "Type-safe way to represent nil values: Optional<T> enum with .none and .some(T)"
      syntax: "var name: String?; if let unwrapped = name { }"
      notes: Force unwrap (!) crashes on nil; use guard let for early exit
    - name: Protocol-Oriented Programming
      introduced: Swift 2.0
      description: Define behavior via protocols with default implementations in extensions
      syntax: protocol Drawable { func draw() }; extension Drawable { func draw() { /* default */ } }
      notes: Prefer protocols over inheritance for flexibility and composition
    - name: Generics
      introduced: Swift 1.0
      description: Write flexible, reusable code with type parameters and constraints
      syntax: "func swap<T>(_ a: inout T, _ b: inout T) { (a, b) = (b, a) }"
      notes: "Use where clauses for complex constraints: func process<T: Equatable>(items: [T]) where T: Hashable"
    - name: Result Builder
      introduced: Swift 5.4
      description: DSL-like syntax for building values ( SwiftUI views, async let groups)
      syntax: "@resultBuilder struct HTMLBuilder { static func buildBlock(_ parts: String...) -> String { parts.joined() } }"
      notes: Foundation of SwiftUI's declarative syntax
    - name: async/await
      introduced: Swift 5.5
      description: Structured concurrency with async functions, await keyword, and structured task groups
      syntax: "async func fetchData() async throws -> Data { try await URLSession.shared.data(from: url) }"
      notes: Replaces callback-based patterns; integrates with actors for thread safety
    - name: Actors
      introduced: Swift 5.5
      description: "Reference types with actor isolation: only one task accesses mutable state at a time"
      syntax: "actor BankAccount { var balance: Double; func deposit(_ amount: Double) async { balance += amount } }"
      notes: Prevents data races; await required when accessing from outside
    - name: Property Wrappers
      introduced: Swift 5.1
      description: "Separate property storage logic from definition: @propertyWrapper struct"
      syntax: "@propertyWrapper struct Lazy<T> { var value: T?; var wrappedValue: T { get set } }"
      notes: Used by @State, @Binding, @ObservedObject in SwiftUI
    - name: ARC (Automatic Reference Counting)
      introduced: Swift 1.0
      description: Memory management via reference counting; weak/unowned for breaking retain cycles
      syntax: "weak var delegate: DelegateProtocol?; unowned let owner: Owner"
      notes: No garbage collector; understand strong/weak/unowned to avoid leaks and crashes
