How to get country names and codes ?

NSArray *countryCodes = [NSLocale ISOCountryCodes];

    NSMutableArray *countries = [NSMutableArray arrayWithCapacity:[countryCodes count]];

    

    for (NSString *countryCode in [NSLocale ISOCountryCodes])

    {

        NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];

        NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier];

        [countries addObject: country];

    }

    

    NSDictionary *codeForCountryDictionary = [[NSDictionary alloc] initWithObjects:countryCodes forKeys:countries];

   

        NSLog(@”%@”,codeForCountryDictionary);

Leave a comment