Swift

Apple's modern language for iOS, macOS, and beyond — safe, fast, and expressive.

Object-Oriented
Functional
Protocol-Oriented
Intermediate
2014
Chris Lattner (Apple)

Overview

Swift is a powerful and intuitive programming language developed by Apple for iOS, iPadOS, macOS, tvOS, and watchOS. It is designed to be safe, fast, and expressive. Swift eliminates entire classes of unsafe code through optionals, type safety, and automatic memory management. Its protocol-oriented programming paradigm encourages composition over inheritance.

Key Features

  • Type safety & optionals — Nil safety is enforced at the compiler level
  • Protocol-oriented — Protocols + extensions enable powerful abstractions
  • Value types — Structs and enums are first-class citizens
  • SwiftUI — Declarative UI framework for Apple platforms
  • Playgrounds — Interactive coding environment for experimentation

Code Example

swift
protocol Describable {
    var description: String { get }
}

struct Planet: Describable {
    let name: String
    let moons: Int

    var description: String {
        "\(name) has \(moons) moon\(moons == 1 ? "" : "s")"
    }
}

let mars = Planet(name: "Mars", moons: 2)
print(mars.description) // Mars has 2 moons

Learning Resources

Learning Path

15 topics across 4 sections

1Basics

  • Introduction to Swift — Swift's safety features, Xcode setup, and Playgrounds
  • Variables & Constants — let vs var, type inference, and type annotations
  • Data Types — Strings, Int, Double, Bool, tuples, and Any/AnyObject
  • Control Flow — if/else, guard, switch (pattern matching), for-in, while
  • Optionals — Optional binding, nil coalescing, forced unwrapping, and optional chaining

2Functions & Closures

  • Functions — External/internal names, default values, inout, and throwing functions
  • Closures — Trailing closures, capturing values, @escaping, and shorthand syntax
  • Enums — Associated values, raw values, CaseIterable, and indirect enums

3OOP & Protocols

  • Structs vs Classes — Value vs reference semantics, mutating, and when to use each
  • Protocols — Protocol definition, conformance, extensions, and PATs
  • Generics — Generic types, functions, associated types, and where clauses
  • Extensions — Adding functionality to existing types, protocol extensions

4SwiftUI & Modern Swift

  • SwiftUI Basics — Declarative views, @State, @Binding, @ObservedObject
  • Concurrency — async/await, Task, actor model, and structured concurrency
  • Result Builders — @ViewBuilder and custom DSLs with result builders