0
struct FixedLengthRange {
    var firstValue = 3
}

class Student {
    var age = 3
}

let john = Student()
john.age = 4

let range = FixedLengthRange()
range.firstValue = 4//this is wrong code

why the property of the Class constant instance can change? Structure didn't.

fzh
  • 688
  • 1
  • 6
  • 14
  • Constant doesn't mean you can't change parts of the instance of a class, just the reference to memory can't change, but for value types such as `struct` they become immutable once they are constants – Andrew Li Nov 30 '16 at 03:06
  • i get it,thereis the answer in the apple document.`When an instance of a value type is marked as a constant, so are all of its properties` – fzh Nov 30 '16 at 03:08

0 Answers0