/** * * * store data*/-(Ibaction) SAVEBTN: (ID) Sender {//preferences are specifically used to save configuration information for an application, and in general do not save other data in preferences//If you use System Preferences to store data, the default is to store it under the Preferences folder.//Preferences will save all the data in the same file//Get Nsuserdefaults ObjectNsuserdefaults *defaults =[Nsuserdefaults Standarduserdefaults]; //Save Data (if no synchronization occurs after setting up the data, the data is automatically saved to the Preferences folder at a later point in time)[Defaults setobject:@"LNJ"Forkey:@"name"]; [Defaults setobject:@"Mans"Forkey:@"Gender"]; [Defaults Setinteger: -Forkey:@" Age"]; [Defaults setdouble:10.1Forkey:@"Height"]; //let Nsuserdefaults save the data immediately[Defaults synchronize];}/** * Read data **/-(Ibaction) READBTN: (ID) Sender {//1. Get NsuserdefaultsNsuserdefaults *defaults =[Nsuserdefaults Standarduserdefaults]; //2. Get the saved data via NsuserdefaultsNSString *name = [Defaults objectforkey:@"name"]; intage = [Defaults integerforkey:@" Age"]; NSLog (@"%@", name); NSLog (@"%d", age);}
IOS Preferences data Access (Preferences folder)