ios - get NSLocale from country name -


i developing ios swift 3.

i got country name string "japan", "britain", "spain", etc.

i wondering best way generate nslocale instance out country name?

i found localizedstring(forcountrycode:) in document, means have manually parse country name country code in project below:

switch countryname {      case "spain":           "es" } 

is there better way generate locale country name?

you can use corelocation framework. code create dictionary, name of country key, , iso value

    var dictionary = [string : string]()     let arraywithcodes = locale.isoregioncodes     code in arraywithcodes {         let description = locale.current.localizedstring(forregioncode: code)         if description != nil {             dictionary[description!] = code         }     } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -