【发布时间】:2017-10-12 11:31:10
【问题描述】:
在下面的代码中,它在 else 语句从未使用过之后给出经度和纬度警告,如果我的字典不包含经度和纬度值,它们将被设置为 let longitude = Double(151.209900) 并让纬度 = 双(-33.865143)?还是我的守卫让声明有问题
guard let dictionary = snapshot.value as? [String : AnyObject] else { return }
guard let latitude = dictionary["Latitude"] as? String else {
let latitude = Double(-33.865143)
return
}
guard let longitude = dictionary["Longitude"] as? String else {
let longitude = Double(151.209900)
return
}
guard let latDouble = Double(latitude) else { return }
guard let longDouble = Double(longitude) else { return }
【问题讨论】:
-
在你的函数中设置一个断点,并观察如果字典没有“纬度”键的条目会发生什么。 – 这是你的意图吗?