Swift private(set) All In One_private(set) Swift private(set) All In One public private(set) closure



Swift private(set) All In One

SwiftUI

Swift private(set) All In One_private(set)

Getters and Setters

 ​

public private(set)

SDK


struct TrackedString {
// private(set) 对内可修改, 对外可见
private(set) var numberOfEdits = 0
var value: String = "" {
didSet {
numberOfEdits += 1
}
}
}



public private(set)


public struct Counter {
// I specify that only the setter is private!
public private(set) var count: Int
}


​ ​

private(set) === closure



struct Person {
// private(set) 对外只读,对内可写
private(set) var name: String = "xgqfrms"
// func getName() {
// return self.name;
// }
func setName(name: String) {
return self.name = name;
}
// public let age: Int = 18
private var age: Int = 18
// 闭包 closure, 对内开放,对外关闭
func getAge() {
return self.age;
}
func setAge(name: Int) {
return self.age = age;
}
}



refs

   ​

 ​



​ ​





xgqfrms