Ahad Sheriff Ahad Sheriff - 1 year ago 70
Swift Question

How to retrieve data from Firebase Realtime database (Swift)

I have this piece of working code that saves data to Firebase:

let locRef = locationRef.childByAutoId()
let locItem = [
senderId : [
"location": getLocationID()

And I want to retrieve the user's (identified by senderID) "location".

What is the syntax that would allow me to do this?


Answer Source

It sounds pretty straight forward then.

locationRef.child(locItemId).child(senderId).observeSingleEventOfType(.Value, withBlock: { (snapshot) in
        let locationId = snapshot.value!["location"] as! String
    }) { (error) in