По сути, я пытаюсь использовать programmeID в пользовательской таблице и использую этот programmeID для получения сведений о программе в таблице программ.
У меня есть снимок со следующим:
Snap (-M4HUc52LbUqcweHF0MI) {
childFirstName = asdf;
childLastName = aa;
currentDay = 1;
currentSession = 1;
equations = 1;
numerals = 1;
problemSolving = 1;
programmeID = "-M4HUc52LbUqcweHF0MI";
programmeOwner = YSHHHgkPbhNaWcKsdJok4lXmZEK2;
quantityRecognition = 1;
tapToProceed = 1;
}
, и я пытаюсь получить их значения и сохранить их в моей собственной структуре программ в коде ниже. Я не уверен, что я делаю неправильно, но как я могу получить их ценность и сохранить их? Что такое конвенция? По какой-то причине я не могу найти документацию по этому вопросу.
usersRef.child(currentUserID!).child("programmes").observeSingleEvent(of: .value, with: { (snapshot) in
// Only
if (snapshot.childrenCount > 0) {
let programmesRef = Database.database().reference().child("programmes")
for data in snapshot.children.allObjects as! [DataSnapshot] {
let data = data.value as? [String:Any]
let currProgID = data!["programmeID"] as! String
programmesRef.child(currProgID).observeSingleEvent(of: .value, with: {(snapshot) in
print(snapshot)
// let individualProgrammes = Programmes(childFirstName: data["childFirstName"] as! String, childLastName: data["childLastName"] as! String, currentDay: data["currentDay"] as! Int, currentSession: data["currentSession"] as! Int, quantityRecognition: data["quantityRecognition"] as! Bool, equations: data["equations"] as! Bool, problemSolving: data["problemSolving"] as! Bool, numerals: data["numerals"] as! Bool, tapToProceed: data["tapToRegister"] as! Bool)
})
programmesRef.child(currProgID).observeSingleEvent(of: .value, with: {(snapshot) in
let firstName = snapshot.childSnapshot(forPath: "childFirstName")
let lastName = snapshot.childSnapshot(forPath: "childLastName")
let day = snapshot.childSnapshot(forPath: "currentDay")
let session = snapshot.childSnapshot(forPath: "currentSession")
let quantityRecognition = snapshot.childSnapshot(forPath: "quantityRecognition")
let equations = snapshot.childSnapshot(forPath: "equations")
let problemSolving = snapshot.childSnapshot(forPath: "problemSolving")
let numerals = snapshot.childSnapshot(forPath: "numerals")
let tapToRegister = snapshot.childSnapshot(forPath: "tapToRegister")
let individualProgrammes = Programmes(childFirstName: firstName as! String, childLastName: lastName as! String, currentDay: day as! Int, currentSession: session as! Int, quantityRecognition: quantityRecognition as! Bool, equations: equations as! Bool, problemSolving: problemSolving as! Bool, numerals: numerals as! Bool, tapToProceed: tapToRegister as! Bool)
print(individualProgrammes)
Буду признателен за помощь. Спасибо, ребята!