Created
May 4, 2020 05:15
-
-
Save Josscii/865d8a2943700a798a3c70e84fa8ab48 to your computer and use it in GitHub Desktop.
比较好的 UserDefaults 的用法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://developer.apple.com/videos/play/wwdc2019/212 | |
extension UserDefaults { | |
private static let isInfoBarHiddenKey = "IsInfoBarHidden" | |
@objc dynamic var isInfoBarHidden: Bool { | |
get { bool(forKey: UserDefaults.isInfoBarHiddenKey) } | |
set { set(newValue, forKey: UserDefaults.isInfoBarHiddenKey) } | |
} | |
} | |
func testUserDefaults() { | |
let _ = UserDefaults.standard.observe(\UserDefaults.isInfoBarHidden, options: .initial) { (_, value) in | |
if let newValue = value.newValue { | |
print(newValue) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment