gpt4 book ai didi

ios - 从 Parse.com 中的指针检索 pfobject 数据的问题

转载 作者:行者123 更新时间:2023-11-28 22:06:41 28 4
gpt4 key购买 nike

我在从解析查询中获取的对象中的指针获取数据时遇到问题。我在查询中使用了 include 键,但是在从返回的对象数组中获取 include 键信息时遇到了问题。我创建了一个 for 循环来遍历结果,但不确定如何将它们存储回数组中。下面是我的代码:

- (void) loadUsersPFUserIsFollowing
{


//Retrieving PFUser Curren Users followers and storing in Array
PFQuery *queryFollowingCount = [PFQuery queryWithClassName:@"Activity"];
[queryFollowingCount whereKey:@"type" equalTo:@"follow"];
[queryFollowingCount whereKey:@"fromUser" equalTo:[PFUser currentUser]];

//Access the the user following informatioin
[queryFollowingCount includeKey:@"toUser"];

//[queryFollowingCount setCachePolicy:kPFCachePolicyCacheThenNetwork];

[queryFollowingCount findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
[HUD hide:YES];
if (!error) {

searchResultsArray = [[NSArray alloc] initWithArray:objects];

NSLog(@"%@", objects);

for (PFObject * postObject in objects) {

PFObject *postAuthor = [postObject objectForKey:@"toUser"][@"username"];



NSLog(@"retrieved related Post Author: %@", postAuthor);
}

[self.tableView reloadData];

} else {
NSLog(@"Something went wrong");
NSLog(@"%@", error);
}
}];

}

最佳答案

for (PFObject * postObject in objects) {
PFObject *postAuthor = [postObject objectForKey:@"toUser"][@"username"];

NSLog(@"retrieved related Post Author: %@", postAuthor);
}

默认情况下,在获取对象时,不会获取相关的 PFObject。在像这样获取这些对象之前,无法检索它们的值:

for (PFObject * postObject in objects) {

//Im assuming in your code, postObject is either nil or it's there but it's values are nil except its objectId. We need to fetch this object.
[postObject fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error){

PFObject *postAuthor = [object objectForKey:@"toUser"][@"username"];

NSLog(@"retrieved related Post Author: %@", postAuthor);

[self.tableView reloadData];

}];
}

关于ios - 从 Parse.com 中的指针检索 pfobject 数据的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23765632/

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