这里是代码:
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:]:此类不符合键值编码规范,无法为键名设置值。'
请帮我修复这个问题,谢谢。