Iphone gets the current system language

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.