Ios 我试图删除一个pin码,但出现了以下错误:无法分配类型为';CLLocationManager';输入';CLLocationCoordinate2D';
根据错误说明,无法将Ios 我试图删除一个pin码,但出现了以下错误:无法分配类型为';CLLocationManager';输入';CLLocationCoordinate2D';,ios,swift,Ios,Swift,根据错误说明,无法将CLLocationManager对象分配给CLLocationCoordinate2D类型的属性 您需要将代码更改为: @IBAction func drop(sender: AnyObject) { let mapAnnotation = MKPointAnnotation() mapAnnotation.coordinate = locationManager // Cannot assign value of type 'CLL
CLLocationManager
对象分配给CLLocationCoordinate2D
类型的属性
您需要将代码更改为:
@IBAction func drop(sender: AnyObject)
{
let mapAnnotation = MKPointAnnotation()
mapAnnotation.coordinate = locationManager // Cannot assign value of type 'CLLocationManager' to type 'CLLocationCoordinate2D'
mapAnnotation.title = "If you want a title"
mapAnnotation.subtitle = "or subtitle"
myMap.addAnnotation(mapAnnotation)
}
由于各种原因,location
属性可以是nil
,强制展开将导致崩溃。因此,最好使用安全的展开:
mapAnnotation.coordinate = locationManager.location!.coordinate
参考资料:
根据错误说明,无法将
CLLocationManager
对象分配给CLLocationCoordinate2D
类型的属性
您需要将代码更改为:
@IBAction func drop(sender: AnyObject)
{
let mapAnnotation = MKPointAnnotation()
mapAnnotation.coordinate = locationManager // Cannot assign value of type 'CLLocationManager' to type 'CLLocationCoordinate2D'
mapAnnotation.title = "If you want a title"
mapAnnotation.subtitle = "or subtitle"
myMap.addAnnotation(mapAnnotation)
}
由于各种原因,location
属性可以是nil
,强制展开将导致崩溃。因此,最好使用安全的展开:
mapAnnotation.coordinate = locationManager.location!.coordinate
参考资料:
实际上模拟器停止了,我的线程1 Exc坏了Instruction@SonnySluiter:这是由于强制展开造成的,您应该使用安全展开,请检查更新的答案实际上模拟器已停止,我的线程1 Exc错误Instruction@SonnySluiter:这是由于强制展开,您应该使用安全展开,请检查更新的答案