IOS: country code

后端 未结 3 1913
逝去的感伤
逝去的感伤 2020-12-28 22:15

I have this code to obtain a code country, but I want to see all code country available; then I can do some \"if\" to implement in my app

NSLocale *local         


        
3条回答
  •  误落风尘
    2020-12-28 22:58

    Better to rely on the NSLocale for countryCode & other language/locale dependent strings. For example: Egypt in Russian is Египет. Avoid using hardcoded country lists like https://stackoverflow.com/a/22660792/342794.

    Use [NSLocale ISOCountryCodes].

    // Example:
    for (NSString *code in [NSLocale ISOCountryCodes])
    {
        // Convert the code to a name: 
        NSString *countryName = [[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:code];
    }
    

    From NSLocale.h; look at other similar properties

    @property (class, readonly, copy) NSArray *availableLocaleIdentifiers;
    @property (class, readonly, copy) NSArray *ISOLanguageCodes;
    @property (class, readonly, copy) NSArray *ISOCountryCodes;
    @property (class, readonly, copy) NSArray *ISOCurrencyCodes;
    @property (class, readonly, copy) NSArray *commonISOCurrencyCodes;
    

提交回复
热议问题