gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:55:38 24 4
gpt4 key购买 nike

您好,我是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com