我有两个叫FollowersPosts的类。像这样的东西:

Follower =(user , follower),用户和关注者都包含Pointers

Posts = (post, postedBy),此处发布者包含Pointers。我想检索当前用户本身的帖子posted以及当前用户关注的用户发布的帖子。我正在尝试:

func loadData() {

    var queryFollowers:PFQuery = PFQuery(className: "Followers")
        queryFollowers.whereKey("follower", equalTo: PFUser.currentUser()!)
    var postQuery:PFQuery = PFQuery(className: "Posts")
        postQuery.whereKey("postedBy", matchesQuery: queryFollowers)

    var postQueryCurrentUser:PFQuery = PFQuery(className: "Posts")
        postQueryCurrentUser.whereKey("postedBy", equalTo: PFUser.currentUser()!)
    var compoundQuery = PFQuery.orQueryWithSubqueries([postQuery, postQueryCurrentUser])
        compoundQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

            if let objects = objects {

                for object in objects {

                    self.data.addObject(object)
                    println(self.data)

                }

            }

    }
}


所以我该怎么做呢?谢谢你的时间..

最佳答案

又是我。同样,我不是iOS开发人员,而是Android,但我熟悉Parse API。您应该阅读有关Compund查询的Parse iOS开发人员指南。

再创建2个查询,因此总共有四个查询:


查找所有关注者(queryFollowers)
查找关注者的所有帖子(postQuery)
查找当前用户的所有帖子NEW
通过复合查询合并查询2和3 NEW

func loadData(){

var queryFollowers:PFQuery = PFQuery(className: "Followers")
    queryFollowers.whereKey("follower", equalTo: PFUser.currentUser()!)
var postQuery:PFQuery = PFQuery(className: "Posts")
    postQuery.whereKey("postedBy", matchesQuery: queryFollowers)
var postQueryCurrentUser:PFQuery = PFQuery(className: "Posts")
    postQueryCurrentUser.whereKey("postedBy", equalTo:PFUser.currentUser())
PFQuery *compoundQuery = [PFQuery orQueryWithSubqueries:@[postQuery,postQueryCurrentUser]];


[compoundQuery findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) { // results contains posts from current user and followers}];


我不确定语法。但我希望你能明白。另外,请考虑接受我对您昨天问题的回答。 =)

10-08 08:27