无法将CLLocation转换为NSValue - 使用坐标?

时间:2018-06-15 07:01:39

标签: ios swift class casting mapkit

我有下载的cloudkit记录,每个记录都有一个位置属性(lat& long)。当我将每个记录设置为for循环中的MKAnnotation类,CLLocationCoordinate2D属性,然后运行...我收到标题所声明的错误。

这是我收到的 - enter image description here

为什么我甚至要处理NSValue财产?我的班级和CkRecord只有坐标。

let location = res.value(forKey: "Location") 
print("RUN PLEASE")
self.pin = AnnotationPin(title: res.value(forKey: "Name") as! String, subtitle: "Address", theCoordinates: location as! CLLocationCoordinate2D, theWeb: "https://google.com")

1 个答案:

答案 0 :(得分:1)

CLLocationCLLocationCoordinate2D是不相关的不同类型。但是CLLocation具有coordinate属性。

将位置投放到CLLocation并使用coordinate

let location = res.value(forKey: "Location") as! CLLocation
self.pin = AnnotationPin(title: res.value(forKey: "Name") as! String, 
                      subtitle: "Address", 
                theCoordinates: location.coordinate, 
                        theWeb: "https://google.com")
相关问题