【发布时间】:2019-05-03 01:55:55
【问题描述】:
我正在使用 Firebase 数据库,并尝试通过 NSObject 检索和使用数据。我在运行应用程序时收到NSUnknownKeyException 错误,导致它崩溃。
NSObject:
class WatchList: NSObject {
var filmid: Int?
}
Firebase 代码:
ref.child("users").child(uid!).child("watchlist").observe(DataEventType.childAdded, with: { (info) in
print(info)
if let dict = info.value as? [String: AnyObject] {
let list = WatchList()
list.setValuesForKeys(dict)
print(list)
}
}, withCancel: nil)
我不确定是什么原因造成的。
此外,增强此解决方案是他们获取此数据的一种方式,而不是使用 NSObject,而是将 Codable 和 JSONDecoder 与 Firebase 数据一起使用?
【问题讨论】:
标签: json swift firebase codable