What does the snapshot/observer code do in firebase?

后端 未结 2 1229
灰色年华
灰色年华 2021-01-27 07:19

When retrieving data from Firebase, we typically use the code below (or some reiteration of it)

...observeSingleEvent(of: .value, with: { snapshot in

var tempPo         


        
2条回答
  •  长情又很酷
    2021-01-27 08:19

    This code is used for observing data change in your database. You don't need to send requests from time to time for getting the latest data.

    When the data changes, it will trigger the closure you given so that you can do things. For more reference, you could read this doc.

    You could try this to covert snapshot into dictionary:

    for child in snapshot.children {
        let dataS = child as! DataSnapshot
        let dict = dataS.value as? [String : AnyObject]
        // handle the data
    }
    
    

提交回复
热议问题