我正在尝试按照这个appcoda GoogleMaps教程并转换为swift 2.我真的很擅长快速理解。
do {
let dictionary = try NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary
} catch let error as NSError {
print("Error")
completionHandler(status: "", success: false)
}; else {
// Get the response status.
let status = dictionary["status"] as String
if status == "OK" {
let allResults = dictionary["results"] as Array<Dictionary<NSObject, AnyObject>>
self.lookupAddressResults = allResults[0]
我在“else”之前收到错误,它首先推荐“;”因为连续的陈述,但后来它在同一个地方出现“预期表达”错误。我发誓我以前做过这个没有错误。我无法理解为什么。这是与一个糟糕的尝试,捕获,做什么有关?感谢任何见解,谢谢。
答案 0 :(得分:0)
@pirateKyle
我认为你应该这样做
do {
let dictionary = try NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers) as! Dictionary<NSObject, AnyObject>
// Get the response status.
let status = dictionary["status"] as! String
if status == "OK" {
let allResults = dictionary["results"] as! Array<Dictionary<NSObject, AnyObject>>
self.lookupAddressResults = allResults[0]
// Keep the most important values.
self.fetchedFormattedAddress = self.lookupAddressResults["formatted_address"] as! String
let geometry = self.lookupAddressResults["geometry"]as! Dictionary<NSObject, AnyObject>
self.fetchedAddressLongitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lng"] as! NSNumber).doubleValue
self.fetchedAddressLatitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lat"]as! NSNumber).doubleValue
completionHandler(status: status, success: true)
}
else {
completionHandler(status: status, success: false)
}
} catch let error as NSError {
completionHandler(status: "", success: false)
print(error)
}