#9: Immutable Variables
Question
// Swift Quiz
— objc.io (@objcio) April 17, 2019
extension CGSize {
mutating func scale(by f: CGFloat) {
width *= f
height *= f
}
}
let s = CGSize(width: 100, height: 100)
s.scale(by: 2)
// What's the value of s?
Solution
Solution: Compiler error
— objc.io (@objcio) April 18, 2019
s is declared with let, and scale is a mutating method on CGSize.
We cannot call mutating methods on let variables.https://t.co/s7500CWmAg