gpt4 book ai didi

ios - 解析好友请求处理

转载 作者:行者123 更新时间:2023-11-29 12:50:35 25 4
gpt4 key购买 nike

我正在解析查询以检查好友请求。查询返回对象,我可以记录它们。现在,当我将它转换为 PFUSER 和 NSLog 时,它会因错误而崩溃:'Key "FirstName"没有数据。在获取其值之前调用 fetchIfNeeded。' 请帮我解决这个问题。

PFQuery * friendQuery = [PFQuery queryWithClassName:@"friendship"];

[friendQuery whereKey:@"toUser" equalTo:[PFUser currentUser]];
[friendQuery whereKey:@"status" equalTo:@"Pending"];
[friendQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error)
{
//NSLog error
}
else {
NSLog(@"friendRequestCount = %d", objects.count);

PFObject *object=[objects objectAtIndex:0];
NSLog(@"%@", object);

self.friendRequestArray= objects;
NSLog(@"%@",object[@"toUser"]);

PFUser *user1= object[@"toUser"];
NSString *friendName = [NSString stringWithFormat:@"%@ %@",user1[@"FirstName"], user1[@"LastName"] ];
NSLog(@"name= %@",friendName);

}
}];

最佳答案

你可以使用 1 或 2,我已经注释了下面的代码,没有测试。

PFQuery * friendQuery = [PFQuery queryWithClassName:@"friendship"];

[friendQuery whereKey:@"toUser" equalTo:[PFUser currentUser]];
[friendQuery whereKey:@"status" equalTo:@"Pending"];
//1
[friendQuery includeKey:@"toUser"];
[friendQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error)
{
//NSLog error
}
else {
NSLog(@"friendRequestCount = %d", objects.count);

PFObject *object=[objects objectAtIndex:0];
NSLog(@"%@", object);

self.friendRequestArray= objects;
NSLog(@"%@",object[@"toUser"]);

PFUser *user1= object[@"toUser"];

//2 Change PFUser to PFObject
PFObject *user1 = object[@"toUser"];
[user1 fetchIfNeeded];

NSString *friendName = [NSString stringWithFormat:@"%@ %@",user1[@"FirstName"], user1[@"LastName"] ];
NSLog(@"name= %@",friendName);

}
}];

关于ios - 解析好友请求处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22526620/

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