如何通过使用swift在firebase中搜索该键来获取密钥的值。 说,具有以下结构,我想通过搜索userID3来检索userName3作为String?
users-used
userID1 : userName1
userID2 : userName2
userID3 : userName3
userID4 : userName4
答案 0 :(得分:2)
Assuming that the 'users-used' directory is at the root of the structure you should be able to it in the following way:
Database.database().reference().child("users-used").child("userID3").observeSingleEvent(of: .value) { (snapshot) in
guard let username = snapshot.value as? String else {
return
}
// username will be available here as a string if successful
}
Keep in mind that everything in the closure will be run asynchronously and can return at any time