当我尝试从Firebase提取数据时,无法将NSNumber桥接到Float

时间:2019-06-05 15:41:41

标签: swift firebase

我无法从Firebase获取数据。我尝试从Firebase获取数据。 除了这两行,一切都很好。

 func calculateDailyAmountOfCalories() {
    let uid = Auth.auth().currentUser?.uid
    let ref = Database.database().reference()
    ref.child("users").child(uid!).observe(.value) { (snapshot) in
        self.userWeight = snapshot.childSnapshot(forPath: "weight").value as!  Float
        self.userHeight = snapshot.childSnapshot(forPath: "height").value as! Float
        self.userAge = snapshot.childSnapshot(forPath: "age").value as! Float
        **var newUserGoal = snapshot.childSnapshot(forPath: "userGoal").value as? Float
        var newUserLevelActivity = snapshot.childSnapshot(forPath: "activityLevel").value as? Float**
        print(newUserGoal)
        print(newUserLevelActivity)



        print(self.userWeight)
        print(self.userHeight)
    }
}

当我尝试获取(var newUserGoal和newUserLevelActivity)data without as?/! Float时,我可以在终端Optional(0.2)中看到一个answear。当我尝试使用as?时,结果为零。 为什么其他类似的快照可以工作,但为什么不能呢?

0 个答案:

没有答案