我正在使用解析框架,想知道如何查询位于 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/