Swift和Xcode:如何拥有默认的国家/地区列表?

Ant*_*ine 2 ios swift

嗨,我是Xcode和Swift的新手.

我正在编写一个应用程序代码,用户可以从列表中选择一个国家/地区,以便为地图添加一个图钉.

基本上,它只是一个带引脚的地图.

我在哪里可以获得默认国家/地区列表?像下拉或其他东西,所以我不需要自己硬编码所有国家.

然后,我知道下一个问题很大,所以我只期待一些指导:

有人可以给我任何指示如何使用所选国家的GPS坐标,以便它将一个图钉放在地图上?

谢谢大家的帮助.

Jam*_*mil 9

试试这个.

func counrtyNames() -> NSArray{

    var countryCodes = NSLocale.ISOCountryCodes()
    var countries:NSMutableArray = NSMutableArray()

    for countryCode  in countryCodes{
        let dictionary : NSDictionary = NSDictionary(object:countryCode, forKey:NSLocaleCountryCode)

        //get identifire of the counrty
        var identifier:NSString? = NSLocale.localeIdentifierFromComponents(dictionary as! [String : String])

        let locale = NSLocale.currentLocale()
        //get country name
        let country = locale.displayNameForKey(NSLocaleCountryCode, value : countryCode)//replace "NSLocaleIdentifier"  with "NSLocaleCountryCode" to get language name

        if country != nil {//check the country name is  not nil
            countries.addObject(country!)
        }
    }
    NSLog("\(countries)")
    return countries
}
Run Code Online (Sandbox Code Playgroud)