gpt4 book ai didi

ios - iOS解析如何从基于两个类的查询中检索对象?

转载 作者:行者123 更新时间:2023-12-01 18:56:13 25 4
gpt4 key购买 nike

我有两个类UserPostUser类具有userType字段,我想从给定的userType检索所有帖子,我们将其称为组x。在Post类中,我有一个指向User类的指针。

我试图做类似的事情,首先检索我想要的用户类型的所有用户ID:

PFQuery *queryUser = [PFQuery queryWithClassName:kFTUserClassKey];
[queryUser whereKey:kFTUserTypeKey equalTo:kFTUserTypeX];
[queryUser whereKey:kFTUserLocationKey nearGeoPoint:nearGeoPoint withinMiles:miles];
[queryUser findObjectsInBackgroundWithBlock:^(NSArray *usersTypeX, NSError *error) {
if (!error) {
NSMutableArray *objectIds = [[NSMutableArray alloc] init];

// Add ambassador ids into query
for (PFObject *userX in usersTypeX) {
[objectIds addObject:[PFObject objectWithoutDataWithClassName:kFTUserClassName objectId: userX.objectId]];
}
}
}];

然后我想基于这些objectIds进行查询,但是我不确定如何在此数组上进行查询,或者这是否是执行此操作的正确方法。如何才能做到这一点?

最佳答案

解析为查询提供了matchesQuery方法,因此...

PFQuery *innerQuery = [PFQuery queryWithClassName:@"User"];
[innerQuery whereKey:@"userType" equalTo:@"X"]; // fix with your real user type
PFQuery *query = [PFQuery queryWithClassName:@"Post"];
[query whereKey:@"user" matchesQuery:innerQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray *posts, NSError *error) {
// posts are posts where post.user.userType == X
}];

关于ios - iOS解析如何从基于两个类的查询中检索对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26701999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com