Jef's answer aiutato qui, con lievi aggiunte.
NSArray *countryCodes = [NSLocale ISOCountryCodes];
NSMutableArray *countries = [NSMutableArray arrayWithCapacity:[countryCodes count]];
for (NSString *countryCode in countryCodes)
{
NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];
NSString *country = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_UK"] displayNameForKey: NSLocaleIdentifier value: identifier];
[countries addObject: country];
}
NSDictionary *codeForCountryDictionary = [[NSDictionary alloc] initWithObjects:countryCodes forKeys:countries];
Passare attraverso la 'codeForCountryDictionary' con il nome del paese per il quale si richiede il codice, ad esempio,
NSLog(@"%@",[codeForCountryDictionary objectForKey:@"Spain"]);
sarebbe cedere il risultato come 'ES', che è il 2 codice paese lettera per la Spagna.
Come va il codice dal nome del paese? Basta fare il contrario :) – deanWombourne
Spero che questo vi aiuterà a linke http://stackoverflow.com/questions/502764/iphone-obtaining-a-list-of-countries-in-an-nsarray –
Ive già controllato, ma quello che voglio è quello di ottenere un solo CountryCode secondo un nome di paese, non un elenco di paesi – pdrcabrod