Swift
Learn Swift by extending the file, process, value, error, and debugging model you already built. Each chapter adds one value, state, ownership, task, package, test, or Apple-platform relationship, produces exact evidence, and states which stronger claim remains unproved.
Your first Swift 5.7 program: source, compiler, binary, and output
Objective Save one complete Swift source file, compile it under warnings-as-errors, run one binary, and compare exact evidence.
Core explanation
A Swift source file is plain text. In this chapter swiftc parses and type-checks main.swift, compiles the selected Swift 5 language mode, links one local native binary, and reports diagnostics before that binary can run. The source, compiler, binary, process, standard output, standard error, and exit status are separate objects. Run swiftc --version first and stop if Swift 5.7 is unavailable. Save the complete file with a final newline, compile with swiftc -swift-version 5 -warnings-as-errors main.swift -o hello-swift, execute ./hello-swift, and inspect status zero separately. No package manifest, Xcode project, download, Apple SDK UI, network, or signing step is needed.
Trace one saved Swift file through one compiler command
Begin with only four objects: main.swift is saved source text, swiftc is the compiler driver, hello-swift is the linked binary, and one running process produces the language line. Source is not a binary, and a binary is not a running process. Keeping those nouns separate exposes a stale-artifact mistake immediately: editing main.swift does not alter an already built hello-swift.
This first chapter deliberately has no Package.swift, Xcode project, Playground, SDK UI, package download, network, signing identity, or Apple developer account. Work in one disposable folder containing only main.swift and the generated binary. If swiftc --version does not establish Swift 5.7 or later, stop at the setup boundary instead of treating editor coloring as compilation evidence.
Read one immutable binding and interpolation before learning projects
let completed = 1 creates one local immutable Int binding. The print call creates visible text, and the backslash-parenthesis interpolation reads completed into that String. Read the example from data to effect: one value is constructed, one expression formats it, and one standard-library call writes one line. No object graph, closure, package, asynchronous task, UI, or external resource is hidden in the example.
Change only 1 to 2 and predict the complete new line before rebuilding. If any other field changes, the prediction or source changed beyond the controlled experiment. This narrow change teaches more than adding framework syntax because every difference has one plausible owner. Restore 1 before beginning another defect.
Separate compiler diagnostics, program output, and terminal status
swiftc -swift-version 5 chooses the declared language mode. -warnings-as-errors makes an owned warning block the new artifact instead of being silently ignored. main.swift supplies the source, -o names the binary, and a successful status is required before that binary represents the current file. Executing ./hello-swift produces the language line; the shell reports exit status zero afterward.
Standard output, standard error, and exit status are different evidence channels. The program must not print exit=0 itself because that would only be another claim from inside the program. Preserve the compiler version, exact command, diagnostics, build status, program output, and run status. One successful run proves this local source-to-process loop, not portability, reproducible bytes, packaging, signing, or deployment.
Laboratory: expose, diagnose, and repair a stale Swift binary
Compile and run the baseline, edit completed without rebuilding, and execute the old binary. Explain why its output remains unchanged. Next rebuild and require the new value. Introduce one syntax fault, confirm compilation fails, and observe that an older binary may still remain on disk. Never use that old file as evidence for the failed source.
Restore the exact baseline, compile cleanly, run, and compare both evidence lines. Then copy only main.swift into a new empty folder and repeat. Another learner should identify source, compiler, binary, process, output, error, and status without an IDE. The transfer is complete when the loop works from the copied file and every observation has one named producing command.