ios - swift 和 Xcode : How to have a default list of countries?

标签 ios swift

您好,我是 Xcode 和 Swift 的新手。

我正在编写一个应用程序,用户可以在其中从列表中选择一个国家,以便它向 map 添加图钉。

基本上,它只是一张带有图钉的 map 。

我在哪里可以获得默认国家/地区列表?比如下拉菜单之类的,这样我就不需要自己对所有国家/地区进行硬编码。

然后,我知道下一个问题很重要,所以我只希望得到一些指导:

有人可以告诉我如何使用所选国家/地区的 GPS 坐标以便在 map 上放置图钉吗?

谢谢大家的帮助。

最佳答案

试试这个。

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
}

关于ios - swift 和 Xcode : How to have a default list of countries?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32584040/

相关文章:

ios - 如何下载 CoreCrypto.framework?

ios - UITabBar - 更新 alpha 值并渲染它? ( swift )

iphone - 在未来的应用程序版本中维护核心数据

ios - swift xcode 更改状态栏(背景颜色)

arrays - 从数组值中查找 Firebase Child - xcode 8/swift 3

ios - 使用步进器限制数组中可以包含的对象数量(swift)

ios - 将分配的缓冲区添加到 NSMutableDictionay

ios - XCTest 中 viewDidLoad 的设置值

ios - 一些残留内存从未通过 ARC 释放?

ios - Swift 中触发 UITextField 错误