junioriOS

What are variables in Swift (let vs var)?

Updated May 6, 2026

Short answer

let defines constants and var defines mutable variables.

Deep explanation

let is used when value should not change after assignment, improving safety. var allows reassignment. Swift encourages immutability by default to reduce bugs.

Real-world example

Use let for API base URLs and var for changing UI states like loading indicators.

Common mistakes

  • Using `var` everywhere instead of preferring `let`.

Follow-up questions

  • Why does Swift prefer immutability?
  • Can a let constant hold a mutable object?

More iOS interview questions

View all →