【发布时间】:2016-11-24 13:24:23
【问题描述】:
代码如下:
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:]:此类不符合键名的键值编码。”
请帮我解决这个问题。
【问题讨论】:
-
在 Message 中创建一个变量名。它将解决问题
标签: swift firebase firebase-realtime-database