gpt4 book ai didi

swift - 当数据库中有一个键时解析对象崩溃

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

所以我试图更改用户自己编写的聊天中所有行的背景颜色。为此,我检查用户的 facebookID 是否与数据库消息中的 facebookID 匹配。

但由于某种原因,我的消息数据库上的 .valueForKey 不断崩溃。

var myUser:PFUser = PFUser.currentUser()!
var queryId = PFQuery(className: "Messages")

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.messageTableView.dequeueReusableCellWithIdentifier("messageCell") as! ChatTableViewCell
cell.textLabel?.text = messagesArray[indexPath.row]

let getUser = myUser.valueForKey("facebookID")
print(getUser)

let getIDUser = queryId.valueForKey("facebookID")
print(getIDUser)

//if getUser == getIDUser {
// make cell red
//}
return cell
}

这会在 getIDUser 的控制台中返回以下内容

reason: '[<PFQuery 0x133dadf10> valueForUndefinedKey:]: this class is not key value coding-compliant for the key facebookID.'

因此 getIDUser 返回错误,但我不知道为什么,因为数据库和 key 确实存在。 enter image description here

最佳答案

问题是这个

var messageDB:PFObject = PFObject(className:"Messages")

创建新的消息对象。您确实可以将其添加到数据库中。

但是要从商店获取对象,您必须执行查询。 Here are more info.

关于swift - 当数据库中有一个键时解析对象崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36033299/

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