Save user information (saved in sandbox)-(void) Saveuserinfo {Nsuserdefaults *defaults = [Nsuserdefaults Standarduserdefaults];//IOS 8.0 will be written directly to the sandbox, no need to use ' [defaults synchronize]; ' [Defaults setobject:
1. archive path, you must use static variable 1. The parameter must be static variable 2 when saving the user account . Static variables need to be loaded only once, and when called, they do not need to be loaded.
static private Let Accountpath = Nssearchpathfordirectoriesindomains (Nssearchpathdirectory.documentdirectory, Nssearchpathdomainmask.userdomainmask, True). last!. Stringbyappendingstring ("Account.plist")
2. Save the user account,
Func Saveaccount () {
Nskeyedarchiver.archiverootobject (self, ToFile:UserAccount.accountPath)
}
Solution-If not saved, the result may still be nil
UserAccount = Nskeyedunarchiver.unarchiveobjectwithfile (Accountpath) as? UserAccount
MARK: Archive (This is the attribute of my own definition)
Func Encodewithcoder (Acoder:nscoder) {
Acoder.encodeobject (Access_token, Forkey: "Access_token")
Acoder.encodedouble (expires_in, Forkey: "expires_in")
Acoder.encodeobject (Expiresdate, Forkey: "Expiresdate")
Acoder.encodeobject (UID, forkey: "UID")
Acoder.encodeobject (name, Forkey: "Name")
Acoder.encodeobject (Avatar_large, Forkey: "Avatar_large")
}
Solution file
Required init? (Coder Adecoder:nscoder) {
Access_token = Adecoder.decodeobjectforkey ("Access_token") as? String
expires_in = Adecoder.decodedoubleforkey ("expires_in")
Expiresdate = Adecoder.decodeobjectforkey ("Expiresdate") as? NSDate
UID = Adecoder.decodeobjectforkey ("UID") as? String
Name = Adecoder.decodeobjectforkey ("name") as? String
Avatar_large = Adecode
}
about how data is saved (sandbox, archive (Swift method))