Constants and variables, type inference, string interpolation, and control flow. The safe, concise foundations of Swift — statically typed, but with the lightness of a scripting language.
Swift distinguishes constants (let) from variables (var) and encourages let — immutable values are easier to reason about and the compiler optimizes them. Types are inferred from the initial value, so you rarely write them, yet everything is statically typed and checked at compile time. This "immutable by default, inferred, but safe" trio defines Swift’s feel.
let name = "Ada" // constant, inferred as String — can't change
var count = 0 // variable — can reassign
count += 1
let pi: Double = 3.14 // explicit type annotation when you want it
// name = "Bob" // COMPILE ERROR: cannot assign to a 'let' constant
print(name) // Ada
// prefer 'let'. Reach for 'var' only when the value genuinely must change.Swift builds strings by embedding expressions inline with backslash-parenthesis syntax — cleaner than concatenation and used everywhere. (In this course’s source the backslash is doubled so the site renders it; in real Swift you write a single backslash before the parenthesis.)
let name = "Ada"
let items = ["a", "b", "c"]
print("Hello, \(name)!") // Hello, Ada!
print("You have \(items.count) items") // any expression inside \( )
print("Upper: \(name.uppercased())") // method calls work too
// \(expression) beats "Hello, " + name + "!" — the idiomatic way to format.Swift’s control flow reads familiarly — if/else, for-in over ranges and collections, while — with a powerful switch that must be exhaustive and supports pattern matching, ranges, and value binding. Exhaustive switches mean the compiler catches a case you forgot, a recurring Swift theme of safety through completeness.
let score = 85
// switch is exhaustive and supports ranges + binding
let grade: String
switch score {
case 90...100: grade = "A"
case 80..<90: grade = "B" // half-open range
case 0..<80: grade = "C"
default: grade = "?"
}
for i in 1...3 { print(i) } // 1 2 3 (closed range)
for item in ["x", "y"] { print(item) }
print(grade) // BSwift has strong value types for numbers, booleans, and strings, plus three core collections: arrays (ordered), sets (unique), and dictionaries (key-value). They are value types with a rich API, and like everything in Swift they are strongly typed — an [Int] holds only integers. These are the everyday building blocks the rest of the language operates on.
var scores = [90, 85, 72] // [Int] — ordered
scores.append(100)
let names: Set = ["Ada", "Bo"] // unique elements
let ages = ["Ada": 36, "Bo": 25] // [String: Int] dictionary
print(scores.count) // 4
print(names.contains("Ada")) // true
print(ages["Bo"] ?? 0) // 25 (subscript returns an Optional)
// collections are strongly typed + value types (copied on assignment).