class ShareData {
static let userDefault = UserDefaults.standard
static var aaaa: String {
get {
return userDefault.string(forKey: "text") ?? "测试默认文字"
}
set(newValue) {
userDefault.setValue(newValue, forKey: "text")
}
}
}
运用:
let str = ShareData.aaaa
ShareData.aaaa = "哈哈哈"
print(str)
let aaa = ShareData.aaaa
print(aaa)