Я пытаюсь выяснить, как сопоставить строки, которые являются UID Firebase в моем массиве «данных», с ключами, которые я извлекаю из вызова firebase.Мне нужно сопоставить строки в массиве «data» с «ключом», и тогда я смогу манипулировать данными так, как я хочу.
var data = [String]()
Database.database().reference().child("Businesses").observe(.value, with: { snapshot in
guard let allUsers = snapshot.children.allObjects as? [DataSnapshot] else {return}
print(allUsers)
print("Printing all users right here")
for user in allUsers {
let key = user.key
print(key)
print("Printing the keys right here come and check this out in the print")
}
})
Моя попытка, ответ не в этом коде
Database.database().reference().child("Businesses").observeSingleEvent(of: .value, with: { snapshot in
self.businessUID = snapshot.value as? NSDictionary
if let dict = snapshot.value as? NSDictionary {
for item in dict {
let json = JSON(item.value)
let businessUid = json["uid"].stringValue
for uid in self.data {
if uid == businessUid {
Database.database().reference().child("Businesses").observe(.value, with: { snapshot in
guard let allUsers = snapshot.children.allObjects as? [DataSnapshot] else {return}
print(allUsers)
print("Printing all users right here")
for user in allUsers {
let key = user.key
print(key)
print("Printing the keys right here come and check this out in the print")
if key == uid {
print(key)
print("printing the matching keys here")
}
}
})
print(uid)
print("Printing the uids here")
Database.database().reference().child("Businesses").child(self.businessessuids).observe(.value, with: { snapshot in
print(snapshot)
print(self.businessessuids)
})
}
}
}
}
})
ОБНОВЛЕНИЕ: Найдены совпадающие значения, но невозможно сохранить
Database.database().reference().child("Businesses").observe(.value, with: { snapshot in
if snapshot.exists() {
for snapChild in snapshot.children {
if let user: Dictionary? = (snapChild as! DataSnapshot).value as? [String : AnyObject] {
let businessUID = user!["uid"] as! String
for uid in self.data {
if uid == businessUID {
let key = uid.jsonKey
print(key)
//print(uid)
print("checking uid's")
//let name = user.childSnapshot(forPath: "name").value as! String
let Ref = Database.database().reference().child("testing")
let saveUID = Ref.child(key).child("their_name")
}
}
}
}
}
})