解析iOS-如何从另一个类查询PFUser详细信息 [英] Parse iOS - How to query PFUser details from another class

查看:68
本文介绍了解析iOS-如何从另一个类查询PFUser详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的iOS社交应用编写一个解析查询,该查询将显示关注活动用户的所有用户.这是我到目前为止的内容:

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];

当前,这正确地给了我所有其他用户之后的活动用户的所有记录,但这并没有为我提供相应记录的PFUser详细信息(用户个人资料图片,显示名称等).关于如何在一个查询中轻松绘制出PFUser详细信息的任何想法?

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?

预先感谢

推荐答案

下面是查询的一些示例代码,我使用它来跟踪所有用户,跟踪所有用户的帖子,以及从当前用户获取的所有帖子.用户.我希望这会有所帮助!

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"];

这篇关于解析iOS-如何从另一个类查询PFUser详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆