Search courses, chapters, or pages...
Compare Xcode command-line projects, Swift Playgrounds, and Terminal workflows by how much setup they need, how fast feedback appears, and whether they support typed console input.
Use what you learned in the previous lesson to solve real-world problems.
Install the tool you plan to use, then confirm Swift is available with Xcode, Swift Playgrounds, or `swift --version` in Terminal. Recognize the difference between Swift itself and an editor that helps you write it.
Trace a tiny Swift file from the first line to the last line it runs. See why first Swift programs can be written as top-level statements without wrapping everything in a class or a special `main` function.
Check what you understood with a short quiz.
Use `print()` to send text and simple results to the output area. Predict how several `print()` calls appear in order, one line at a time.
Create a macOS Command Line Tool project, find `main.swift`, press Run, and read the debug console. Connect Xcode’s red markers, build messages, and console output to the code you just ran.
Create a Swift Playground, type a few statements, and use the live results area or console to see what happened. Notice why Playgrounds are great for experiments but not always the right place for standard terminal input.
Save a file such as `hello.swift`, run it with `swift hello.swift`, and read output directly in Terminal. Use the file and line numbers in Terminal messages to jump back to the code that caused them.
Compile a Swift file with `swiftc`, run the executable it creates, and know when edits require rebuilding. Separate the one-time build step from the separate step of launching the finished program.
Start an executable project with `swift package init --type executable`, locate the generated source file, and run it with `swift run`. Use Swift Package Manager as the repeatable command-line workflow for programs that grow beyond one file.
Use `readLine()` in a command-line program to wait for the user to type a line of text. Print a prompt before reading, then echo the response so the program visibly reacts to input.
Recognize when your program is paused because it is waiting for input rather than broken. Stop it with Xcode’s Stop button or `Control-C` in Terminal, then rerun after changing the code.
Use compiler messages to find the file, line, and kind of mistake that prevented your program from running. Practice fixing simple issues like missing quotes, misspelled names, or unmatched parentheses, then run again.
Tell whether a problem happened before launch, while the program was running, or only in the output you printed. Match build errors, runtime crashes, and normal console text to the places they appear in Xcode, Playgrounds, and Terminal.
Review this chapter with practice based on your mistakes.