Store data with preference settings and store data with preference settings
// Preference settings are used to save application configuration information. Generally, do not store other data in preference settings. // if you use system preference settings to store data, by default, all the data stored in the Preferences folder is saved to the same file. // The NSUserDefaults object NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults] is obtained. // Save the data (if the data is not synchronized after the data is set, the data will be automatically saved to the Preferences folder at a certain time point in the future) as follows: [defaults setObject: @ "lnj" forKey: @ "name"]; [defaults setObject: @ "man" forKey: @ "gender"]; [defaults setInteger: 13 forKey: @ "age"]; [defaults setDouble: 10.1 forKey: @ "height"]; // Let NSUserDefaults immediately Save the synchronization data: [defaults synchronize]; // read the data stored in the preference settings: // 1. obtain nsuserdefasnsnsuserdefaults * defaults = [NSUserDefaults standardUserDefaults]; // 2. use NSUserDefaults to obtain the saved data NSString * name = [defaults objectForKey: @ "name"]; int age = [defaults integerForKey: @ "age"];