首先,這不是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