0
Как добавить данные из дочернего элемента в базу данных Firebase? Ниже мой код.Как добавить данные из дочернего элемента в базу данных Firebase?
import UIKit
import Firebase
import FirebaseDatabase
class MedalViewController: UICollectionViewController {
var imagesArray = [String]()
var identities = [String]()
var identities2 = [String]() //Creates an empty array
var imagesArrayGreyed = [String]()
let databaseRef = FIRDatabase.database().reference()
let userID = FIRAuth.auth()?.currentUser?.uid
override func viewDidLoad() {
super.viewDidLoad()
imagesArray = ["1", "2", "3"] //Add all the medal images here
identities = ["Shield", "Tie", "Star"] //Add all the identities here
identities2 = ["Shield"] //Choose what medals the user has.
imagesArrayGreyed = ["1Greyed","2Greyed","3Greyed"] //Add all the greyed images here
databaseRef.child("users").child(userID!).observeSingleEventOfType(.Value, withBlock: { (snapshot) in
// Get user value
var newIdentities2 = snapshot.value!["medals"] as! String
// how do I continue on from here?
// ...
}) { (error) in
print(error.localizedDescription)
}
}
Вот картина моей Firebase структуры данных:
данные должны быть получены только один раз, когда ViewController
открыт, а затем добавляется в массив. Спасибо за вашу помощь.
Edit: Намерение состоит в том, чтобы получить данные от firebase ребенка «медали» и добавить его в локальный массив «identifier2»