+ 2
why the value still can be changed
class C{ var a = 5 } let c = C() c.a = 6 c.a = 7 print(c.a) // why the value still can be changed even though we use let
2 Antworten
+ 1
You don't change the value of your var c, just the value of one of its attributes. That's a big difference. c is still the same object and remains, even if you modify the value of any attribute. OOP basics.
+ 1
PS: easy cross-check for you, try this:
let c = C() // valid
c.a = 0 // valid
c = C() // failure