private(set) with let properties - 'private(set)' modifier cannot be applied to read-only properties
问题 I'm already aware of how private(set) works. But the below code is give compile-time error, class Person { private(set) let name: String //Error. private(set) let age: Int //Error. init(name: String, age: Int){ self.name = name self.age = age } } Error: 'private(set)' modifier cannot be applied to read-only properties Since name and age are not read-only properties, it shouldn't give such an error. If I use let instead of var , it is working fine. Just trying to know why? 回答1: private(set)