Type inference
Swift infers a variable's type from its initializer. Annotate explicitly when there's no initializer or to force a wider/narrower type.
let x = 42 // Int
let y: Double = 42 // Double
var name = "Ada" // String
Languages · 17 sections
Optionals, value types, ARC, structured concurrency and modern Swift 6 — the iOS/macOS interview essentials.
Swift infers a variable's type from its initializer. Annotate explicitly when there's no initializer or to force a wider/narrower type.
let x = 42 // Int
let y: Double = 42 // Double
var name = "Ada" // String
let creates an immutable binding; var a mutable one. For value types, let also makes the value immutable. Prefer let by default.
let pi = 3.14
// pi = 3 // error
var count = 0
count += 1
Int (platform-sized, 64-bit on modern), Double, Float, Bool, String, Character, UInt. Int is the default integer literal type. Use Int (not UInt) for general arithmetic to avoid conversion friction.
let i: Int = 1
let d: Double = 1.0
let b: Bool = true
let c: Character = "A"
135 more cards in this sheet
Unlock the Languages bundle — ₹399
One-time payment. Unlocks this sheet and 7 other sheets in the bundle, plus a typeset PDF of each.
Unlock the bundle See all bundles
Or get all 76 sheets for ₹999 — one payment, every future sheet included.
What's new and the interview questions people are actually getting asked. No spam.