首先,这不是What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"该类不是密钥值编码兼容的密钥XXX - 类正确确认?
我已经看过这个问题和一些其他人,并已确保我的课是通过身份检查以及连接检查连接的重复。我的课程也通过助理编辑器中的自动模式显示出来。
if let currentUser = FIRAuth.auth()?.currentUser {
ref = FIRDatabase.database().reference()
ref.child("Teams").child(self.teamName.text!).setValue(["Name" : self.teamName.text!])
ref.child("Teams").child(self.teamName.text!).setValue(["Number" : self.teamNumber.text!])
ref.child("Teams").child(self.teamName.text!).setValue(["Password" : self.teamPassword.text!])
ref.child("Teams").child(self.teamName.text!).setValue(["memberCount" : 1])
print("1")
let userName = "member" + String(1)
let currentUserEmail = currentUser.uid
ref.child("Teams").child(self.teamName.text!).child("memberList").setValue([userName : currentUserEmail])
print("2")
if let userteamcount = self.ref.child("Users").child(currentUser.uid).value(forKey: "teamCount") as? Int {
let currentTeam = "team" + String(userteamcount + 1)
print("4")
self.ref.child("Users").child(currentUser.uid).setValue(["teamCount" : (userteamcount + 1)])
print("5")
self.ref.child("Users").child(currentUser.uid).child("joinedTeams").setValue([currentTeam : self.teamNumber.text!])
print("6")
}
}
一个重要的注意事项是它在发送错误之前打印出1和2。
而且,这里的specfic错误,我得到:
1
2
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<FIRDatabaseReference 0x618000054160> valueForUndefinedKey:]:
this class is not key value coding-compliant for the key teamCount.'
非常感谢。
'子(currentUser.uid).value的(forKey: “teamCount”)'崩溃,因为你是假设这'child'有一个'teamCount'性质和它doesn “T。 – matt