-1
let myclassInstance1 = myclass()
let myclassInstance2 = myclassInstance1
myclassInstance1.prop1 = 2
myclassInstance2.prop1 = 3

This code is supposed to throw error as I am altering the constant.

But it's not happening.

How come?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    Related: [Why constant constraints the property from a structure instance but not the class instance?](http://stackoverflow.com/questions/38010936/why-constant-constraints-the-property-from-a-structure-instance-but-not-the-clas) – Hamish Nov 30 '16 at 11:40

1 Answers1

4

The class instance is not constant. Just the reference is.

This means you cannot do this:

let myClassInstance = MyClass()
myClassInstance = MyClass()
dasdom
  • 13,975
  • 2
  • 47
  • 58