1 , overview
Many iOS apps support preferences such as saving usernames, passwords, font size, and so on, and iOS offers a standard set of solutions to add preferences to your app.
Each app has a Nsuserdefaults instance that accesses preferences. For example, save the user name, font size, and whether to log in automatically.
nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults];
[Defaults setobject: @ "itcast" forkey: @ "username"];
[Defaults setfloat: 18.0f forkey: @ "Text_size"];
[Defaults setbool: YES forkey: @ "Auto_login"];
[Defaults synchronize];
3. Sync now to synchronize in-memory data with preferences, suggest calling
[Defaults synchronize];
2 , read the last saved settings
Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];
NSString *username = [Defaults stringforkey: @ "username"];
float textSize = [Defaults floatforkey: @ "Text_size"];
BOOL autologin = [Defaults boolforkey: @ "Auto_login"];
Note: When setting the data, Userdefaults does not write immediately, but instead writes the cached data to the local disk according to the timestamp. So after calling the set method, it is possible that the data has not yet been written to the disk application to terminate. The above problem can be forced by calling the Synchornize method to write
[Defaults synchornize];
Preference of data storage for iOS development (preferences)