Swift设置只读(readOnly)属性
class ReadOnly {
private(set) var name: String
init(_ name: String) {
self.name = name
}
}
let obj = ReadOnly.init("hah")
//以下代码会报错
obj.name = "hahh"
class ReadOnly {
private(set) var name: String
init(_ name: String) {
self.name = name
}
}
let obj = ReadOnly.init("hah")
//以下代码会报错
obj.name = "hahh"