gpt4 book ai didi

swift - 快照值作为 int 导致崩溃

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

因此,我正在发出好友请求,在获取这些请求后,我收到了错误。

this class is not key value coding-compliant for the key xxx

发送请求工作正常(these are the values from sending a request):

let fromId = (Auth.auth().currentUser!.uid)
let toId = self.otherUser?["uid"] as! String

let senderFriendRef = databaseRef.child("friendship").child(fromId)
senderFriendRef.updateChildValues([toId : 0])
let receiverFriendRef = databaseRef.child("friendship").child(toId)
receiverFriendRef.updateChildValues([fromId : 1])

这是获取请求的代码。我玩弄了 if (snapshot.value as? Int == 1) ,这似乎会导致崩溃,因为在我收到错误说我无法将其转换为 Int:

if let loggedInUser = Auth.auth().currentUser?.uid {
Database.database().reference().child("friendship").child(loggedInUser).observe(.childAdded) { (snapshot) in
if (snapshot.value as? Int == 1) {
let requestId = snapshot.key
Database.database().reference().child("users").child(requestId).observeSingleEvent(of: .value, with: { (snapshot) in
if let dict = snapshot.value as? [String : AnyObject] {
let person = Person()//model
person.setValuesForKeys(dict)
person.id = requestId
self.friendRequest.append(person)
print(self.friendRequest)
DispatchQueue.global().async {
DispatchQueue.main.async {
self.collectionView.reloadData()
//ending brackets

最佳答案

永远不要使用setValuesForKeys,你只会遇到很多问题。 This其他帖子帮助我解决了这个问题。

关于swift - 快照值作为 int 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51849943/

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