swift 添加两个带有 '[String : CLLocation]' 的数组



有可能吗,如果是的话,我将如何将这两个数组加在一起?

let ausCities = ["Sydney": CLLocation(latitude: -33.865143, longitude: 151.209900),"Wagga Wagga": CLLocation(latitude: -35.1082, longitude: 147.3598)]
let usaCanadacitiesArray = ["Atlanta": CLLocation(latitude: 33.7490, longitude: 84.3880),"Austin": CLLocation(latitude: 30.2672, longitude: 97.7431),"Baltimore": CLLocation(latitude: 39.3000, longitude: 76.6105)]

尽管有变量名称,但您正在处理字典,而不是数组。 如果你想组合它们,请查看 Swift 标准库中对合并函数的描述。 它提供了有关处理重复键的详细信息。

例:

let allCities = ausCities.merging(usaCanadacitiesArray) { (current, _) in current }

最新更新