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.
Values
- The program shapeThe smallest Swift: top-level code, print, interpolation.
- let and varConstants by default, mutation by request, types by inference.
- String interpolationBackslash-parens splice values; triple quotes span lines.
Control flow
- if and guardguard bails early so the happy path stays unindented.
- switch patternsExhaustive matching over ranges, wheres, and tuples.
- Ranges and loops1...3 includes the end, 0..<3 stops short, stride steps.
Functions & closures
- Argument labelsCall sites read like prose; underscores opt out.
- ClosuresTrailing braces and $0: the shape of everyday Swift.
- map, filter, reduceThe functional trio, plus compactMap for the misses.
Optionals
- OptionalsThe maybe-missing value, spelled into the type.
- if let and guard letUnwrap by shadowing: same name, non-optional inside.
- Optional chainingOne ? short-circuits the whole path to nil.
Collections
- Arrays and dictionariesValue-type collections with literal syntax.
- enumerated and zipWalk with indices, or walk two sequences in lockstep.
- SetsDeduplication plus algebra: union, intersection, subtracting.
Structs & classes
- Structs are valuesAssignment copies; writers say mutating.
- Classes are referencesTwo names, one object; === asks about identity.
- Computed propertiesDerived on read, observed on write.
Abstractions
- Protocols and extensionsState the requirement; share the implementation.
- Associated valuesEnum cases carry payloads; switch unpacks them.
- GenericsType parameters at the call site, bounded where needed.
Errors & scope
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.