Skip to content
let and var
step 1/5

Reading — step 1 of 5

Learn

~1 min readGetting Started

Swift has two binding keywords:

  • let — constant (read-only)
  • var — variable
let name = "Alice"      // can't reassign
var count = 0            // can reassign
count = count + 1
// name = "Bob"          // compile error

let age: Int = 30         // explicit type

Default to let. The compiler will warn if you use var for something that's never reassigned.

Basic types: Int, Double, Float, Bool, String, Character. Type names start with a capital. There's no implicit conversion — the compiler refuses to mix Int and Double without an explicit Double(intValue).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…