试图对地址进行地理编码的例外情况

时间:2016-11-04 16:58:21

标签: ios swift

我有以下代码导致异常,我不知道为什么。一旦在XCode中遇到异常,我就无法继续找出异常是什么 - 我的意思是通常你可以继续在XCode中执行,你可以检查调用堆栈以查看异常的原因,但是这种情况下,当我单击继续程序执行按钮时,它只是不断地粘在屏幕截图中的特定行。

let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString("Infinite Loop,Cupertino,California", completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
    print("WTF")
} as! CLGeocodeCompletionHandler)

enter image description here

该项目与MapKit框架链接。

1 个答案:

答案 0 :(得分:0)

你的语法都错了。你不应该试图强迫任何东西。假设您需要Swift 3:

let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString("Infinite Loop,Cupertino,California", completionHandler: { (placemark: [CLPlacemark]?, error: Error?) -> Void in
    // do stuff
})

甚至更简单:

let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString("Infinite Loop,Cupertino,California") { (placemark: [CLPlacemark]?, error: Error?) -> Void in
    // do stuff
}