gpt4 book ai didi

dictionary - Swift - map 注释的更好方法

转载 作者:行者123 更新时间:2023-11-30 10:21:50 24 4
gpt4 key购买 nike

嘿,我目前正在开发一个小应用程序,但我的内存使用量非常高。该应用程序有大约 200 个 map 注释,这些注释是这样添加的:

    //Number: 1 Airport: Lukla  - Mount Everest
let location1:CLLocationCoordinate2D = CLLocationCoordinate2DMake(AirportLat[1], AirportLong[1])
let info1 = CustomPointAnnotation()
info1.coordinate = location1
info1.title = AirportTitle[1]
info1.imageName = AirportimageName[1]
Map.addAnnotation(info1)

//Number: 2 Airport: Helgoland
let location2:CLLocationCoordinate2D = CLLocationCoordinate2DMake(AirportLat[2], AirportLong[2])
let info2 = CustomPointAnnotation()
info2.coordinate = location2
info2.title = AirportTitle[2]
info2.imageName = AirportimageName[2]
Map.addAnnotation(info2)

//Number: 3 Airport: Aspen
let location3:CLLocationCoordinate2D = CLLocationCoordinate2DMake(AirportLat[3], AirportLong[3])
let info3 = CustomPointAnnotation()
info3.coordinate = location3
info3.title = AirportTitle[3]
info3.imageName = AirportimageName[3]
Map.addAnnotation(info3)

来 self ,所以我得到了一些数组,但由它自己创建每个注释(但所有“数组只是一一计数”)我确信有更好的方法来做到这一点,任何人都可以给我一些提示如何减少这个,也许可以使用 for/while 来实现这个? :( 我没有任何工作

最佳答案

枚举其中一个数组,然后创建注释数组。然后,您可以将所有注释一次性添加到 map View 中。

var allAnnotations =  [CustomPointAnnotation]()
for (index, value) in enumerate(AirportLat){
let annotation = CustomPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(AirportLat[index], AirportLong[index])
annotation.title = AirportTitle[index]
annotation.imageName = AirportimageName[index]
allAnnotations += [annotation]
}

Map.addAnnotations(allAnnotations)

关于dictionary - Swift - map 注释的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26032281/

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