且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

加入Firebase数据库

更新时间:2023-02-02 22:50:49

eventAttendees/fm 下,您有多个孩子.因此,您也需要遍历代码中的那些子节点:

Under eventAttendees/fm you have multiple children. So you will need to loop over those child nodes in your code too:

let ref = Database.database().reference()
ref.child("eventAttendees/fm").observe(.value, with: { (snapshot) in
    for child in snapshot.children.allObjects as [FIRDataSnapshot] {
        print (child.key)
        ref.child("users/\(child.key)").observeSingleEvent(of: .value, with: { (userSnapshot) in
            let content = userSnapshot.value as? [String : AnyObject] ?? [:]
            print(content["name"])
        })
    }
})