有人能否建议一种更简洁的方法来从CLPlacemark创建地址字符串。
目前,我正在使用以下扩展:
extension CLPlacemark {
func makeAddressString() -> String {
var address = ""
if subThoroughfare != nil { address = address + " " + subThoroughfare! }
if thoroughfare != nil { address = address + " " + thoroughfare! }
if locality != nil { address = address + " " + locality! }
if administrativeArea != nil { address = address + " " + administrativeArea! }
if postalCode != nil { address = address + " " + postalCode! }
if country != nil { address = address + " " + country! }
return address
}
}
所有实例变量都是可选的,因此需要检查是否为nil,并且我希望以相同的顺序显示街道号码、街道等。