gpt4 book ai didi

ios - swift 3 firebase 快照如果值等于...获取

转载 作者:行者123 更新时间:2023-11-28 12:18:54 24 4
gpt4 key购买 nike

enter image description here

我正在尝试检查房间的值“所有者”是否等于当前用户 ID,如果是,则获取包括键值在内的所有数据并继续检查“房间”的其他 child

我一直在尝试,但我没有找到解决方案,尽管它看起来很简单,所以请帮助我提供您的建议或想法。到目前为止我的代码:

          Database.database().reference().child("rooms").queryOrdered(byChild: "Owner").observeSingleEvent(of: .value, with: { (snapshot) in

let currentUser = Auth.auth().currentUser?.uid

if !snapshot.exists() {
print("No data found")
return
}

var rooms = snapshot.value as! [String:AnyObject]
let roomKeys = Array(rooms.keys)

for roomKey in roomKeys {

guard

let value = rooms[roomKey] as? [String:AnyObject]

else
{
continue
}

let title = value["title"] as? String
let description = value["description"] as? String
let roomPictureUrl = value["Room Picture"] as? String
let longitude = value["Longtitude"] as? String
let latitude = value["Latitude"] as? String
let dateFrom = value["Date From"] as? String
let dateTo = value["Date To"] as? String
let owner = value["Owner"] as? String

let myRooms = Room(roomID: roomKey,title: title!, description: description!, roomPicutreURL: roomPictureUrl!, longitude: longitude!, latitude: latitude!, dateFrom: dateFrom!, dateTo: dateTo!, owner: owner!)

self.rooms.append(myRooms)
self.tableView.reloadData()

print(snapshot.value)

}
})

最佳答案

您缺少查询中的值:

Database.database().reference()
.child("rooms")
.queryOrdered(byChild: "Owner")
.queryEqual(toValue: "STbz...")
.observeSingleEvent(of: .value, with: { (snapshot) in

有关此和更多查询运算符,请参阅 documentation on filtering data .

关于ios - swift 3 firebase 快照如果值等于...获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45471099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com