iosswift

how to update user default value in swift?


I have dictionary value saved in user default plist that save user email and login status like this

let userData : [String:Any] = [

"email" : StringValue
"hasBeenLoggedIn : BooleanValue

]

UserDefaults.standard.set(userData, forKey: "userData")

enter image description here

i want to update the value of hasBeenLoggedIn to true(Yes). how do i do that in swift ?


Solution

  • Try this

    var rr  = UserDefaults.standard.dictionary(forKey: "userData")
    rr?["hasBeenLoggedIn"] = true
    UserDefaults.standard.set(rr, forKey: "userData")