从另一个 class 重置扩展文件 userdefualt
reset extension file userdefualt from another class
将用户默认计数重置为来自扩展方法之外的函数。在这种情况下,它的功能很简单。现在代码从 0 开始,除非我可以使用 func 来阻止代码上升。
extension UIViewController {
func updateVisitCount() {
let key = String(describing: type(of: self))
let count = UserDefaults.standard.value(forKey: key) as? Int ?? 0
UserDefaults.standard.set(count + 1, forKey: key)
}}
class easy: UIViewController {
@IBAction func delete() {
//reset let count to 0
}}
再做一个功能就是这样
extension UIViewController {
func updateVisitCount() {
let key = String(describing: type(of: self))
let count = UserDefaults.standard.value(forKey: key) as? Int ?? 0
UserDefaults.standard.set(count + 1, forKey: key)
}
func clearVisitCount() {
let key = String(describing: type(of: self))
UserDefaults.standard.set(0, forKey: key)
}
}
class easy: UIViewController {
@IBAction func delete() {
//reset let count to 0
self.clearVisitCount()
}
}
将用户默认计数重置为来自扩展方法之外的函数。在这种情况下,它的功能很简单。现在代码从 0 开始,除非我可以使用 func 来阻止代码上升。
extension UIViewController {
func updateVisitCount() {
let key = String(describing: type(of: self))
let count = UserDefaults.standard.value(forKey: key) as? Int ?? 0
UserDefaults.standard.set(count + 1, forKey: key)
}}
class easy: UIViewController {
@IBAction func delete() {
//reset let count to 0
}}
再做一个功能就是这样
extension UIViewController {
func updateVisitCount() {
let key = String(describing: type(of: self))
let count = UserDefaults.standard.value(forKey: key) as? Int ?? 0
UserDefaults.standard.set(count + 1, forKey: key)
}
func clearVisitCount() {
let key = String(describing: type(of: self))
UserDefaults.standard.set(0, forKey: key)
}
}
class easy: UIViewController {
@IBAction func delete() {
//reset let count to 0
self.clearVisitCount()
}
}