Learn to Code Special! | 30% off ALL ACCESS to One Month ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

Hide

Let's Never Change

Introduction to Swift ยท Lesson 6 ยท


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

MyPlayground.playground

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'