【发布时间】:2019-02-15 12:51:25
【问题描述】:
我正在使用 Firebase 实时数据库,但我需要一些帮助来解决这个问题。
这是我的代码:
let usersDB = Database.database().reference().child("user/\(username)")
usersDB.observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists() {
self.lblUserAvailability.text = "Not Available"
}
else {
self.lblUserAvailability.text = "Available"
}
})
}
我想要的是,如果用户已经存在于数据库中,它应该转到“snapshot.exists()”语句,但在我的情况下,它总是转到 else 语句。 我的数据库结构是:
用户
-LXa4s3d9BrGqDThdWU-
用户名“rashid55”
【问题讨论】:
-
删除此
child("user/\(username)")并添加此child("user") -
但是我想检查一个特定的值我的意思是一个特定的用户名请检查这个图片以获得更好的想法i.stack.imgur.com/8eCSK.png
-
@Rashid Latif 在下面检查我的答案,它会起作用
-
请让我检查一下
标签: ios swift firebase firebase-realtime-database