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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -