解析查询不匹配点 pfuser

parse query doesnotmatch point pfuser

我开发了一个好友关系应用,用户可以添加现有用户为好友。 然后我在做一个搜索朋友的功能,我的 table 结构如下: PFUser --> 记录当前用户(standard class) FriendList --> username(我的用户名), 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) {

            }
        }

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

    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")

搜索时,使用好友用户名不匹配即可

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
}