解析查询不匹配点pfuser

时间:2015-09-08 13:53:26

标签: swift parse-platform point

我开发了一个朋友关系app,用户可以添加现有用户作为朋友。 然后我正在做一个搜索好友函数,我的表结构如下: PFUser - >记录当前用户(标准类) FriendList - >用户名(我的用户名),朋友(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
    }

1 个答案:

答案 0 :(得分:0)

我在添加额外字段“friendusername”时修改了我的代码以保留PFUser.currentUser()。用户名

        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
}