gpt4 book ai didi

ios - 升级到 Xcode 8 和 Swift 3.0 后使用 Google Places iOS SDK 出现无法解释的异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:57:35 26 4
gpt4 key购买 nike

在将其转换为 swift 3.0 后,我什至无法使用演示代码。我已经尝试了我能想到的一切都无济于事。

异常非常无用,堆栈跟踪也是如此。 (见截图)

enter image description here

这是 swift 2.3 代码,运行良好:

@IBAction func getCurrentPlace(sender: UIButton) {

placesClient?.currentPlaceWithCallback({
(placeLikelihoodList: GMSPlaceLikelihoodList?, error: NSError?) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}

self.nameLabel.text = "No current place"
self.addressLabel.text = ""

if let placeLikelihoodList = placeLikelihoodList {
let place = placeLikelihoodList.likelihoods.first?.place
if let place = place {
self.nameLabel.text = place.name
self.addressLabel.text = place.formattedAddress!.componentsSeparatedByString(", ")
.joinWithSeparator("\n")
}
}
})
}

这在 swift 3.0 中是等价的:

@IBAction func go(_ sender: AnyObject) {
var placesClient: GMSPlacesClient?
placesClient = GMSPlacesClient.shared()
placesClient?.currentPlace(callback: {
(placeLikelihoodList: GMSPlaceLikelihoodList?, error: NSError?) in

if let error = error {
print("Pick Place error: \(error.localizedDescription)")
let alert = UIAlertController(title: "Error", message: "Couldn't find a location", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)

return
}

if let placeLikelihoodList = placeLikelihoodList {
let place = placeLikelihoodList.likelihoods.first?.place
if let place = place {
self.testlabel.text = place.name
}
}


} as! GMSPlaceLikelihoodListCallback)
}

异常阻止了我:as! GMSPlaceLikelihoodListCallback

有人知道发生了什么事吗?

最佳答案

    var placesClient: GMSPlacesClient?
placesClient = GMSPlacesClient.shared()
placesClient?.currentPlace(callback: { (place, error) in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
let alert = UIAlertController(title: "Error", message: "Couldn't find a location", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)

return
}

if let placeLikelihoodList = place {
let place = placeLikelihoodList.likelihoods.first?.place
if let place = place {
self.lblOrigem.text = place.formattedAddress
}
}
})

关于ios - 升级到 Xcode 8 和 Swift 3.0 后使用 Google Places iOS SDK 出现无法解释的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39537257/

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