func fetchUser() {
Database.database().reference().child("users").observe(.childAdded, with: { (DataSnapshot) in
if let dictionary = DataSnapshot.value as? [String: AnyObject] {
let user = User()
user.setValuesForKeys(dictionary.)
print(user.name!, user.email!)
}
}, withCancel: nil)
}
用信号SIGABRT私のアプリに自分のfirebaseデータベースからのデータを追加するユーザーの私のアレイへの辞書からの情報を追加するとき、それはSIGABRTエラーがスローされます(私は、オブジェクトを作成しましたために)。私は何をしているのですか?スウィフトエラー - スレッド1:setValuesForKeys
ログにエラーメッセージは、この氏は述べています:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ChatApp.User 0x10bdeec70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.'
*** First throw call stack:
(0x18136a364 0x1805b0528 0x18136a02c 0x181c82630 0x181d1e7dc 0x100016170 0x10001645c 0x10016dd7c 0x100199524 0x1012a92cc 0x1012a928c 0x1012adea0 0x181312544 0x181310120 0x18122fe58 0x1830dcf84 0x18a8af67c 0x100025fbc 0x180d4c56c)
libc++abi.dylib: terminating with uncaught exception of type NSException
例外の理由をよく読んでください。おそらくこのクラスはキーXYZ *のコード値に対応したキー値ではありません。 XYZはクラス内のキーで、辞書と一致しません。ところで、SwiftのKVCのsetValuesForKeysより優れた方法があります。 – vadian