We are facing the following issue with the following API Locale.isoRegionCodes
which has been deprecated from iOS >= 16. The new API is the following Locale.Region.isoRegions
but when doing a mapping like the following the region.identifier
returns the code 001.
if #available(iOS 16, *) {
let CountryCodeWithNewApi = Locale.Region.isoRegions.map { region in
CustomCountry(value: "", key: region.identifier)
}.sorted(by: { $0.value < $1.value })
} else {
// Fallback on earlier versions
}
How do we get the old country codes of 2 letters by deriving it from this code? is it possible or we are required to do a manual mapping of the ISO-3166-alpha 2 codes to be able to display all the country codes to the user?
2
Answers
The expression:
gives the same list as the deprecated:
The following code:
prints:
when run on a macOS Swift Playground in Xcode 15.2 under macOS 14.3.1. It should also be true under iOS (but I haven’t confirmed).
Your code then becomes something like the following:
When run on a macOS Swift Playground in Xcode 15.2 under macOS 14.3.1. It should also be true under iOS (but I haven’t confirmed).
Your code then becomes something