Parse iOS - How to query PFUser details from another class

别说谁变了你拦得住时间么 提交于 2020-01-14 05:18:08

问题


I am trying to write a Parse query for my iOS social app that will show all users that are following the active user. Here is what I have so far:

PFQuery *followingUser = [PFQuery queryWithClassName:@"Activity"];
    [followingUser whereKey:@"Activity" equalTo:@"follow"];
    [followingUser whereKey:@"fromUser" equalTo:self.user];
    [followingUser includeKey:@"User"];
    [followingUser setCachePolicy:kPFCachePolicyCacheThenNetwork];

Currently this correctly gives me all the records of the active user following any other users, But this doesn't give me the PFUser details (user profile pic, display name, etc) for the corresponding records. Any ideas on how i can easily draw out the PFUser details in the one query?

Thanks in advance


回答1:


Here is some sample code of a query that I used to get all the users being followed, all posts from the users being followed, and all posts from the current user. I hope this helps!

// List of all users being followed by current user
PFQuery *followingActivitiesQuery = [PFQuery queryWithClassName:kFTActivityClassKey];
[followingActivitiesQuery whereKey:kFTActivityTypeKey equalTo:kFTActivityTypeFollow];
[followingActivitiesQuery whereKey:kFTActivityFromUserKey equalTo:[PFUser currentUser]];
followingActivitiesQuery.cachePolicy = kPFCachePolicyNetworkOnly;
followingActivitiesQuery.limit = 100;

// Posts from users being followed
PFQuery *postsFromFollowedUsersQuery = [PFQuery queryWithClassName:self.parseClassName];
[postsFromFollowedUsersQuery whereKey:kFTPostUserKey matchesKey:kFTActivityToUserKey inQuery:followingActivitiesQuery];
[postsFromFollowedUsersQuery whereKey:kFTPostTypeKey containedIn:@[kFTPostTypeImage,kFTPostTypeVideo,kFTPostTypeGallery]];

// Posts from current user
PFQuery *postsFromCurrentUserQuery = [PFQuery queryWithClassName:self.parseClassName];
[postsFromCurrentUserQuery whereKey:kFTPostUserKey equalTo:[PFUser currentUser]];
[postsFromCurrentUserQuery whereKey:kFTPostTypeKey containedIn:@[kFTPostTypeImage,kFTPostTypeVideo,kFTPostTypeGallery]];

PFQuery *query = [PFQuery orQueryWithSubqueries:[NSArray arrayWithObjects: postsFromFollowedUsersQuery, postsFromCurrentUserQuery, nil]];
[query includeKey:kFTPostUserKey];
[query orderByDescending:@"createdAt"];


来源:https://stackoverflow.com/questions/26150007/parse-ios-how-to-query-pfuser-details-from-another-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!