There are three simple ways to store data locally: Databases, Nsuserdefaults, and files.
Nsuserdefaults is used to store data with small amounts of data, such as User Configuration. Not all things can be put in, only support: Nsstring,nsnumber, NSDate, Nsarray, Nsdictionary, detailed methods can view the class file.
Nsuserdefaultsstandarduserdefaults is used to record the data of permanent retention is very convenient, do not need to read and write files, but retained in a nsdictionary dictionary, saved to the file by the system, the system will be saved to the application The Library/preferences/gongcheng.plist file. It is important to note that if the program exits unexpectedly, the nsuserdefaultsstandarduserdefaults data is not written to the file by the system, but can be used [[Nsuserdefaultsstandarduserdefaults] Synchronize] command is synced directly to the file to avoid data loss.
First, store the data in Nsuserdefaults:
Uiswitch
-(Ibaction) switchchanged: (ID) sender{
Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];
[Userdefaults setbool:_theswitch.on forkey:@ "Switchvalue"];
}
Uitextfield
-(Ibaction) inputchanged: (ID) sender{
Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];
[Userdefaults setobject:_textfield.text forkey:@ "Inputvalue"];
}
Second, read the data in the Nsuserdefaults:
Uiswitchnsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults]; BOOL SW = [userdefaults boolforkey:@ "Switchvalue"]; [_theswitch seton:sw];//uitextfieldnsstring *str = [userdefaults stringforkey:@ "Inputvalue"]; [_textfield SETTEXT:STR];
Registerdefaults: Method is a subset of the registration preferences, it is not written to the plist file, but in the ND can be taken indeed.
This means that the data you see in the Plist file is the settings you have shown.
Call the Setxxx method, for example
Use of Nsuserdefaults Standarduserdefaults