Get the most from each lesson’s compiled editor—the same habits transfer to Xcode playgrounds, CLI scripts, and CI running swift test.
Recommended workflow
- Read the concept section before editing code.
- Click Run to compile with
swiftcand execute the binary. - Use
print()for debug output—avoid UIKit/SwiftUI imports in runnable snippets. - Change one idea at a time; read compiler errors from top to bottom.
What the runner can and cannot do
- Can — single-file
main.swiftwith top-level code or@main, stdlib and Foundation - Needs local setup — Xcode projects, SwiftUI previews, iOS simulators, multi-target SPM apps
Compare with Kotlin, Go, and C# compiled tracks.
Important interview questions and answers
- Q: What prints to stdout in Swift lessons?
A:print()from the Swift standard library—likeprintlnin Kotlin orfmt.Printlnin Go. - Q: Why avoid UIKit in sandbox code?
A: UIKit requires the iOS/macOS SDK and app lifecycle—not available in a single-file CLI compile.
Self-check
- What filename does the playground expect?
- What should you avoid importing in sandbox code?
Challenge
First compile and run
- Click Run with the default code.
- Confirm output appears in the terminal.
- Add a second
print()with your name.
Done when: the terminal shows the default message and your custom line.
Challenge
First compile and run
- Click Run with default code.
- Confirm terminal output.
- Add a custom
print().
Done when: terminal shows default and your custom line.
Interview prep
- What runs code in the playground?
swiftc compiles main.swift into a binary executed on the macOS toolchain.