Let's Never Change

Introduction to Swift · Lesson 6 · 6 minutes

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: https://github.com/onemonth/one-month-ios


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'