gpt4 book ai didi

swift - 解析查询与 pfuser 不匹配点

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

我开发了一个 friend 关系应用程序,用户可以将现有用户添加为 friend 。然后我正在做一个搜索好友功能,我的表结构如下:PFUser --> 记录当前用户(标准类)FriendList --> 用户名(我的用户名), friend (指向PFUser)

当用户添加关系时:

        var friendListObject = PFObject(className: "FriendList")
friendListObject.setObject(currentUser!.username!, forKey: "myusername")
friendListObject.setObject(result.user, forKey: "friend") //result.user = PFUser
friendListObject.saveInBackgroundWithBlock{
(success: Bool, error: NSError?) -> Void in
if (success) {

}
}

当我想搜索新 friend 时,我的关系中没有的 friend ,我使用了下面的代码,但是,不起作用。有什么建议吗?

    var resultQuery = PFQuery(className: "FriendList")
resultQuery.whereKey("myusername", equalTo: currentUser!.username!)
resultQuery.selectKeys(["friend"])

var query = PFUser.query()

query!.whereKey("username", notEqualTo: currentUser!.username!)
query!.whereKey("objectId", doesNotMatchKey: "friend", inQuery: resultQuery)

query!.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
}

最佳答案

我在添加附加字段“friendusername”以保留 PFUser.currentUser().username 时修改了代码

        var friendListObject = PFObject(className: "FriendList")
friendListObject.setObject(currentUser!.username!, forKey: "myusername")
friendListObject.setObject(result.user, forKey: "friend")
friendListObject.setObject(result.user.objectForKey("username") as! String, forKey: "friendusername")

搜索时,使用friendusername作为不匹配,然后就可以了

var resultQuery = PFQuery(className: "FriendList")
resultQuery.whereKey("myusername", equalTo: currentUser!.username!)
resultQuery.selectKeys(["friend"])

var query = PFUser.query()

query!.whereKey("username", notEqualTo: currentUser!.username!)
query!.whereKey("objectId", doesNotMatchKey: "friend", inQuery: resultQuery)

query!.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
}

关于swift - 解析查询与 pfuser 不匹配点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32459660/

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