Variables and Types
Swift has two ways to declare a binding: let creates a constant — it can be set once and never reassigned — while var creates a variable you can reassign. Swift nudges you toward let as the default; you reach for var only when you genuinely need to change the value later.
let name = "Swift" var count = 0 count = count + 1 print(name + " " + String(count))
Swift 1
Both let and var infer their type from the initializer, but you can also write the type explicitly. Basic types include Int, Double, Bool, and Character — and, as with Kotlin, Bool prints as the lowercase word false, not C#'s capitalized False.
let age: Int = 30
let price: Double = 19.99
let isStudent: Bool = false
let grade: Character = "A"
print("\(age) \(price) \(isStudent) \(grade)")30 19.99 false A
That \(age) syntax is string interpolation — any expression inside \(...) is evaluated and inserted directly into the string, with no separate + concatenation needed. The strings lesson later in this course covers it in more depth.
Next: operators and control flow — if/else, for-in, while, and switch with ranges.
Practice exercise
Declare a Double constant named temperature set to 72.5 and a Bool constant named isSunny set to true, then print both separated by a space using string interpolation.