【发布时间】:2016-08-12 16:06:00
【问题描述】:
我正在尝试转换从 Firebase 检索的字符串并将其添加为 Google 地图上的多个注释。不幸的是,我的应用程序在通过当前代码时崩溃:
ref = FIRDatabase.database().reference()
ref.child("Locations").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
let lat = (snapshot.value!["Latitude"] as! NSString).doubleValue
let lon = (snapshot.value!["Longitude"] as! NSString).doubleValue
let complainLoc = CLLocationCoordinate2DMake(lat, lon)
let Coordinates = CLLocationCoordinate2D(latitude: lat, longitude: lon)
})
这是我用于将数据保存到 Firebase 的代码
FIRDatabase.database().reference().child("Location").child(FIRAuth.auth()!.currentUser!.uid).setValue(["Latitude": locationManager.location!.coordinate.latitude, "Longitude": locationManager.location!.coordinate.longitude])
【问题讨论】:
-
你确定它在创建
CLLocationCoordinate2D的地方崩溃了,而不是你在强制转换/展开的地方崩溃了吗?检查以确保value不是nil。还要检查value["Latitude"]和value["Longitude"]是否 (a) 不是nil,以及 (b) 字符串值。对于所有这些!强制展开和强制转换操作符,这里有很多可能的崩溃来源。 -
complainLoc是干什么用的?
标签: ios swift firebase firebase-realtime-database