Zum Inhalt springen
KodeTrail

Camp 1 · Schritt 2 von 12

Hello, Swift!

print, comments, string interpolation, and the pleasantly minimal anatomy of a Swift program.

10 Min.+50 XPAuf Englisch angezeigt — Übersetzung ist unterwegs

Swift keeps ceremony low: statements run top to bottom, no boilerplate wrapper needed.

Printing

SwiftCloud-Run

print adds a newline each call and accepts several values separated by commas (joined with spaces).

String interpolation

Swift drops expressions into strings with a backslash-parentheses:

let name = "Ada"
let km = 13.0
 
print("\(name) hiked \(km) km")
print("In meters: \(km * 1000)")

Anything inside \( ... ) is evaluated and inserted — Swift's answer to Python's f-strings. You'll write this dozens of times a day.

Types, quietly present

SwiftCloud-Run

Swift infers Int, Double, String — strong types without the paperwork. Mixing them without converting is a compile error; Swift never silently guesses (no JavaScript-style "2" + 2 surprises).

Checkpoint

Which syntax inserts a value into a Swift string?

Checkpoint

let count = 5 — what type does Swift give count?

What's next

let vs. var — and why Swift developers reach for let first, always.