M
M
MarsFM2017-04-01 16:26:34
Swift
MarsFM, 2017-04-01 16:26:34

How to retrieve data from firebase?

Plz tell me how to display data from the database in firebase? how to display information of each id?
There is such data:
47bd34608408403fb685c2a3836be8bf.png
id was generated using NSUUID().uuidString.lowercased()

ref.database.reference().child("game").child("футбол")

user is clear, we write child(user.id) there, but here I don’t understand. Maybe the structure should be done differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nanosem, 2017-04-01
@sportredwhite

FIRDatabase.database().reference().child("game").child("Футбол").observeSingleEvent(of: .value, with: { (snapshot) in
            if let dictionary = snapshot.value as? [String: AnyObject] {
                for index in 0..<dictionary.count {
                    let currentKey = dictionary.keys.sorted()[index] // ID
                    let currentGame = dictionary[currentKey]

                    let adress= currentGame?["address"] as! String // Address
                    // Точно так же остальные поля можно достать
                }
        }
})

This is if you need to get every game from "Football".
For the future - name the fields in the database in English if you are going to work with them in the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question