0Pricing
Swift Academy · Lesson

let vs var, type inference, literals, tuples

Understand let vs var, type inference, numeric/string literals, and tuples for grouping values.

Intro

Swift values can be declared with let (constant) or var (variable). Type inference makes code concise.

let vs var

Use let for constants, var for mutable variables.

// Constant cannot change
let pi = 3.14
// pi = 3.14159 // error: cannot assign to value: 'pi' is a 'let' constant

// Variable can change
var counter = 0
counter += 1
print("counter =", counter)

All lessons in this course

  1. let vs var, type inference, literals, tuples
  2. Core types: numbers, Bool, String, Character
  3. Optionals intro: ?, nil, if let, guard let, ??
← Back to Swift Academy