ios - Storing class in NSUserDefaults and accessing in next view -


i created swift class called userdetails , below structure:

import foundation   class userdetailsclass {     var fullname: string!     var mobile: string!     var email: string!     var password: string! } 

in current view controller , create instance , store values want move next view in instance variables shown below:

var userdetailsinstance = userdetailsclass()             userdetailsinstance.fullname = fullnametextfield.text             userdetailsinstance.mobile = mobiletextfield.text             userdetailsinstance.email = emailtextfield.text             userdetailsinstance.password = passwordtextfield.text              var prefs = nsuserdefaults.standarduserdefaults()             prefs.setobject(userdetailsinstance, forkey: "currentguest")             prefs.synchronize() 

in next view (where there segue connected, try this:

override func viewdidload() {         super.viewdidload()          // additional setup after loading view.         var prefs = nsuserdefaults.standarduserdefaults()         var userdetailsclass: anyobject? = prefs.valueforkey("currentguest")      } 

but app crashes. objective here after user enters his/her details, not store them in server rather in nsuserdefault take them next view sms verification take place. once verification done, store information on server.

the error console showing:

attempt insert non-property list object appname.userdetailsclass key currentguest'

is there better way move data storing object in nsuserdefault?

i beginner ios developer help.

the reason unable store object in nsuserdefaults because not property list type (nsnumber, nsdata, nsarray, nsdictionary, nsdate, string, bool). store in nsuserdefaults, must 1 of these types serialize nsdata, in order need nscoding compliant.

the better solution pass object in prepareforsegue


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -