2018-12-30 15:01:23.228731+0200 iChat[51679:726127] *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键值编码为关键用户名。(lldb)
使用 firebase 字典为 NSobject 类的键设置值
import UIKit
class User: NSObject {
var email: String?
var username: String?
}
功能
func fetchUsers() {
Database.database().reference().child("users").observe(.childAdded) { (snap) in
if let dictionary = snap.value as? [String : AnyObject]{
let user = User()
user.setValuesForKeys(dictionary)
print(user.username)
}
}
}