ios - 查询 PFUser currentUser 以获取自定义字段

标签 ios objective-c parse-platform

我正在使用解析框架,想知道如何查询位于 PFUser 表中的列。

下面是一些示例代码:

//Adds athlete_id column to roster table    
PFObject *roster = [PFObject objectWithClassName:@"Roster"];
roster[@"athlete_id"] = answer;
[roster save];

//Adds the rosters objectId to an array (athlete_id) in the User table. 
PFUser *currentUser = [PFUser currentUser];
[currentUser addObject:roster.objectId forKey:@"athlete_id"];
[currentUser saveInBackground];

通过上面的代码,最终在名为“athlete_id”的列中的 User 类中获得了一个 objectsID 数组。

我在从 User 类中检索这个数组时遇到了问题。这是我尝试从用户那里获取数组的方式:

FQuery *query = [PFUser query];;
    [query whereKey:@"username" equalTo:[PFUser currentUser].username];
    [query whereKeyExists:@"athelete_id"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {

            NSLog(@"athlete %@", objects);

        } else {

            NSLog(@"Error: %@ %@", error, [error userInfo]);

        }
    }];

我想获取当前用户的 athlete_id 列中包含的数组,但此查询中的对象数组为空。

最佳答案

您不需要查询。

只需这样做:

NSString *athleteId = [[PFUser currentUser] objectForKey:@"athelete_id"];

NSLog(@"The athlete id is %@", athleteId);

关于ios - 查询 PFUser currentUser 以获取自定义字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24600207/

相关文章:

ios - com.facebook.sdk.login Code=308 "(null) on iOS10

Objective-C:具有 Split View的 UITabBarController

iphone - 在 iPhone 上使用 NSDateFormatter 格式化日期

javascript - 服务器端和特定时间的脚本执行

javascript - 使用 Angular 和 Parse.com 获取

ios - TableView - heightForRowAtIndexPath 未被调用

iphone - 我可以获取 iOS UIPasteboard 的所有名称吗?

ios - UIDocumentInteractionController 不起作用

iphone - 如何从 ABPeoplePickerNavigationController 获取街道地址

ios - 刷新 PFInstallation.currentInstallation() 时出错