SwiftUI
https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html#ID18
SDK
struct TrackedString {
// private(set) 对内可修改, 对外可见
private(set) var numberOfEdits = 0
var value: String = "" {
didSet {
numberOfEdits += 1
}
}
}
public struct Counter {
// I specify that only the setter is private!
public private(set) var count: Int
}
https://www.natashatherobot.com/swift-magic-public-getter-private-setter/
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;
}
}
https://www.youtube.com/watch?v=4GjXq2Sr55Q&ab_channel=Stanford
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
手机扫一扫
移动阅读更方便
你可能感兴趣的文章