Retrieving Data using Firebase Swift

后端 未结 1 1489
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 12:42

I\'m using Firebase for my Swift iOS application. I found the retrieving data tutorial on Firebase\'s guide a bit confusing and I am not sure why when I try to access existi

相关标签:
1条回答
  • 2020-12-11 12:57

    Your FDataSnapshot does not contain a child firstName. It only contains a child 1.

    This is because you're performing a query and then asking for a value. Since a query can have many results, it returns a list of results. Even when there's only one result, it is still a list of 1.

    The solution is to loop over the children:

    usersRef.queryOrderedByChild("fbid")
            .queryEqualToValue(userId)
            .observeSingleEventOfType(.Value, withBlock:{ snapshot in
                for child in snapshot.children {
                    print("Loading group \(child.key!)") 
                }
    })
    
    0 讨论(0)
提交回复
热议问题