gpt4 book ai didi

swift - 我怎样才能获得所需的数据?

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

    ref = Database.database().reference()

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

let userRef = ref.child("users").child(currentUserID!)

let userRefQuery = userRef.queryOrdered(byChild: "requests").queryEqual(toValue: "received")

userRefQuery.observeSingleEvent(of: .value, with: { (snapshot) in

if (snapshot.value is NSNull) {

print("no data found")
return
}

print("value:")
print(snapshot.value)

print("key:")
print(snapshot.key)

})

Firebase Database

如何获取“requests”下值为“received”的用户的userID。因为它也可能被“发送”。目前,我没有收到任何数据!

最佳答案

这就是我的工作方式:

ref = Database.database().reference()

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

refHandle = ref.child("users").child(currentUserID!).observe(.value, with: { (snapshot) in

print(snapshot)

if let userDict = snapshot.value as? [String: Any] {

if let requests = userDict["requests"] as? [String: String] {

print(requests)

for request in requests {

if request.value == "sent" {

self.userIDs.append(request.key)
print(request.key)

}

}

}


}

}

关于swift - 我怎样才能获得所需的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45903647/

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