typestar

Language basics

27 steps in 9 sets of Swift.

Swift is Apple's 2014 answer to a question Objective-C had carried for thirty years: what would the platform language look like designed fresh? The answer — value types first, optionals instead of nil crashes, protocols over inheritance, closures everywhere — became the language of iOS and macOS development, then grew a serious life on Linux servers and in the Vapor and AWS Lambda worlds. It compiles through LLVM to fast native code and reads closer to a scripting language than its performance suggests.

This tour types the core: let and var, interpolation, guard and the pattern-matching switch, ranges and stride, argument labels, trailing closures with $0, the map/filter/reduce trio, the whole optional toolkit from ?? to guard let to chaining, the value-type collections, structs against classes, computed properties, protocols with extensions, enums with associated values, generics, and errors from throws through Result to defer. The Encore is the cross-language script trio in modern Swift — defaulted subscripts, range patterns, and zip.

Start this tour

Values

Control flow

Functions & closures

Optionals

Collections

Structs & classes

Abstractions

Errors & scope

  • ErrorsTyped throws routed by do, try, and catch.
  • ResultSuccess or failure as a value, switched like any enum.
  • deferCleanup scheduled at entry, run at every exit.

Encore

  • word_freq.swiftA word-frequency table from split, a defaulted subscript, one sort.
  • grade_report.swiftReport cards from a struct roster, range patterns, and format.
  • temp_stats.swiftA week of temperatures: min/max by closure, a bar chart, zip swings.

The other Swift tours