Ahad Sheriff Ahad Sheriff - 5 months ago 23
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?

Thanks!

Answer

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
        print(error.localizedDescription)
}
Comments