I am creating an app that requires to have a UserDefaultManager
. But unfortunately it shows an error:
Use of unresolved identifier 'UserDefaults'
I tried to solve it by declaring a variable like:
let UserDefaults = NSUserDefaults.standardUserDefaults()
but it is still not working for me. Attached below are my codes for your references. Hope you can help me. By the way I am using xcode 10.
struct UserDefaultsManager {
private static let isLoggedInKey = "com.example.key.isLoggedIn"
// let UserDefaults = NSUserDefaults.standardUserDefaults()
static func login() {
UserDefaults.standard.setValue(true, forKey: isLoggedInKey)
UserDefaults.standard.synchronize()
}
static func logout() {
UserDefaults.standard.setValue(false, forKey: isLoggedInKey)
UserDefaults.standard.synchronize()
}
static func isLoggedIn() -> Bool {
return UserDefaults.standard.bool(forKey: isLoggedInKey)
}
}