How do I get a list of countries in Swift ios?

You can get a list of countries using the NSLocale class’s isoCountryCodes which returns an array of [String]. From there, you get the country name by using NSLocale‘s displayName(forKey:) method. It looks like this: var countries: [String] = [] for code in NSLocale.isoCountryCodes { let id = NSLocale.localeIdentifier(fromComponents: [NSLocale.Key.countryCode.rawValue: code]) let name = NSLocale(localeIdentifier: “en_UK”).displayName(forKey: … Read more

How to get country code using NSLocale in Swift 3

You can use regionCode property on Locale struct. Locale.current.regionCode It is not documented as a substitute for old NSLocaleCountryCode construct but it looks like it is. The following code checks countryCodes for all known locales and compares them with regionCodes. They are identical. public func ==(lhs: [String?], rhs: [String?]) -> Bool { guard lhs.count == … Read more