3
下面是代碼:火力地堡夫特3.0 setValuesForKeysWithDictionary
func observeMessages() {
let ref = FIRDatabase.database().reference().child("messages")
ref.observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let message = Message()
message.setValuesForKeys(dictionary)
self.messages.append(message)
//this will crash because of background thread, so lets call this on dispatch_async main thread
DispatchQueue.main.async(execute: {
self.tableView.reloadData()
})
}
}, withCancel: nil)
}
當運行時,它崩潰是這樣的:
終止應用程序由於未捕獲的異常 'NSUnknownKeyException',原因:「[setValue方法:forUndefinedKey :]:這個類不是密鑰名稱的密鑰值編碼。「
請您好好幫我解決這個問題。
在信息創建一個變量名。它會解決這個問題 – junaidsidhu