解析用户配置文件的查询配置文件数据 - Swift

时间:2014-12-30 04:35:33

标签: ios iphone swift parse-platform xcode6

我想根据您在我的应用中使用的个人资料查询用户数据。截至目前,我的查询只获得所有帖子,而不仅仅是个人资料所属的用户。

“Drives”是用户帖子的类名。

 post.removeAll(keepCapacity: false)
    var findTimelineData:PFQuery = PFQuery(className:"Drives")
    findTimelineData.findObjectsInBackgroundWithBlock
        {
            (objects:[AnyObject]! , error:NSError!) -> Void in
            if error == nil
            {
                self.post = objects.reverse() as [PFObject]
                self.table.reloadData()
            }
    }

1 个答案:

答案 0 :(得分:1)

post.removeAll(keepCapacity: false)
var findTimelineData:PFQuery = PFQuery(className:"Drives")

//Add the next line
findTimelineData.whereKey("YOUR_COLUMN_NAME_WHERE_THE_USERS_ARE_STORED", equalTo: "THE_NAME_OF_THE_USER")


findTimelineData.findObjectsInBackgroundWithBlock
    {
        (objects:[AnyObject]! , error:NSError!) -> Void in
        if error == nil
        {
            self.post = objects.reverse() as [PFObject]
            self.table.reloadData()
        }
}

或者您可以选择任何whereKey ...功能,如下所示:https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/whereKey:equalTo

<强>更新: 如果查询指针字段,那么whereKey被修改了一下,你必须使用关系查询:

let userNameQuery = PFQuery(className: "THE_CLASSNAME_WHERE_THE_USERS_ARE_STORED")
userNameQuery.whereKey("YOUR_COLUMN_NAME_WHERE_THE_NAME_OF_THE_USERS_ARE_STORED", equalTo: "THE_NAME_OF_THE_USER")

let findTimelineData:PFQuery = PFQuery(className:"Drives")
findTimelineData.whereKey("POINTER_COLUMN_OF_USER", matchesQuery: userNameQuery)