School's Out for Summer Sale! — 50% off all courses at One Month

Video not found

Let's Never Change

Getting Started: Introduction to Swift · Lesson 5 ·

Bring some stability to your life with Lets.

All of the code that we write in this section and the others is open source and available here in its entirety:


Try out some lets


let myNewString = "test value"
// myNewString = "new test value" // Error: Cannot assign to 'let' value 'myNewString'
let bob: String
bob = "some value"
// bob = "some other value" // Error: Immutable value 'bob' may only be initialized once
let myConstantArray = ["alfie"]
// myConstantArray.append("scrumptious") // Error: Immutable value of type '[String]' only has mutating members named 'append' [constant array cannot be mutated by append]
// myConstantArray = nil // Error: Cannot assign to 'let' value 'myConstantArray'