ios - NSUserDefaults.standardUserDefaults().stringForKey("useremail") value returning null -
i creating login registeration page there error. userstoredemailuser , userstoredpassword returning null when try login. please error.
login code:
let useremail=email.text; let userpassword=password.text; let userstoredemail = nsuserdefaults.standarduserdefaults().stringforkey("useremail") //return null let userstoredpassword = nsuserdefaults.standarduserdefaults().stringforkey("userpassword") //return null // print(emails); // print(userstoredemail);
registreration code:
let useremail=email.text; let userpassword=password.text; let userrepassword = repassword.text; //check empty field //store data let defaults = nsuserdefaults.standarduserdefaults() defaults.setobject("useremail", forkey: useremail!) defaults.setobject("userpassword", forkey: userpassword!) defaults.synchronize() let alert1 = uialertcontroller(title: "alert", message:"registration succesfully complete", preferredstyle:.alert) // add action (button) alert1.addaction(uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil)) presentviewcontroller(alert1, animated: true, completion: nil)
is not
defaults.setobject("useremail", forkey: useremail!) defaults.setobject("userpassword", forkey: userpassword!)
it is, wrongly saved value userdefaults
defaults.setobject(useremail!, forkey: "useremail") defaults.setobject(userpassword!, forkey: "userpassword")
no need of synchronize()
- automatically update userdefaults
Comments
Post a Comment