let uid = FIRAuth.auth()?.currentUser?.uid
let ref = FIRDatabase.database().reference().child("users").child((uid)!)
ref.observeSingleEvent(of: .value, with: { snapshot in
if let dictionary = snapshot.value as? [String: AnyObject] {
let htest = dictionary["h"] as! String //error is mainly here signal SIGABRT
var inthtest = Int(htest)
if (inthtest==0){
self.checkPointsk()
print("scanning1")
我已经尝试将as String Value更改为int Value但它仍然不起作用
答案 0 :(得分:3)
错误是不言自明的。您正在尝试将数字转换为字符串。替换以下两行
let htest = dictionary["h"] as! String
var inthtest = Int(htest)
与
var inthtest = dictionary["h"] as! Int
避免此类崩溃的最佳方法是使用条件绑定。
if var inthtest = dictionary["h"] as? Int{
//Do your stuff
}
else if var inthtest = dictionary["h"] as? String{
if let integerValue = Int(inthtest){
//Do your stuff
}
}