Almost all data in the settings of the iphone is stored in NSUserDefaults. Imagine four data storage methods commonly used by the iphone. NSUserDefaults is indeed an ideal method to save the settings file. Compared with other methods, it is easy to use and meets requirements.
First, let's take a look at the language settings page:
Have you noticed that the language you selected always appears in the first column.
This is an interesting phenomenon. Think about what kind of data structure is more suitable for storing this list of data. I think many people will answer this question in an array.
If the list is saved as an array, the first item is the selected language, that is, the index value of the current language in the array is 0.
The entire structure is clear here. NSUserDefaults uses the (key, array) method to save the language settings data, and the first item of array is the currently selected language. So knowing the key is the key to getting the current language:
[Cpp]
/* Get the current language */
+ (NSString *) currentLanguage
{Www.2cto.com
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
NSArray * ages = [defaults objectForKey: @ "AppleLanguages"];
NSString * currentLanguage = [ages objectAtIndex: 0];
Return currentLanguage;
}
How to find the key?
Documentation, About the User Defaults System or Locale Concepts, are worth reading.
Author: likendsl