假设我的firebase realtime数据库中有子名用户,而子名用户又有子名,这些子名用户是类似于“christialliz@gmail.com”的电子邮件,那么子名用户的电子邮件中还有子名、年龄和国家。
我在child上添加了一个observeevent更改了代码片段,如下所示。
ref.child("USERS").child("christianLiz@gmail,com").observe(.childChanged, with: { snapshot in
if snapshot.exists(){
let value = snapshot.value as? NSDictionary
if value!["name"] != nil{
print("here")
}else{
print("not here")
}
}){ (error) in
print("")
}
当我测试后改变国家的价值,应用程序崩溃,原因是这个价值![姓名]。现在我知道childChanged事件只返回在我的测试场景“country”中更改的子级,所以其他值不在快照中,但我想检查哪个值是更新的名称、年龄或国家。如何修改上面的代码来实现这一点。