#8: Mutable Variables
Question
// Swift Quiz
— objc.io (@objcio) April 10, 2019
func +(l: CGPoint, r: CGPoint) -> CGPoint {
return CGPoint(x: l.x + r.x, y: l.y + r.y)
}
var rect = CGRect(x: 0, y: 0, width: 320, height: 480)
rect.origin + CGPoint(x: 10, y: 10)
// What's the value of rect.origin?
Solution
Solution: (0, 0)
— objc.io (@objcio) April 11, 2019
Although rect is a mutable variable, the + operator doesn't mutate any of its parameters.
The value of rect.origin + CGPoint(x: 10, y: 10) is (10,10), but rect.origin is unchanged.
https://t.co/s7500CWmAg