Reputation: 111
I have a class (table) in Parse.com
core data called users
with username, name, surname, email
and password
.
I want to retrieve, for example, only the name
column but I can't make this work. Here is the code:
PFQuery *query = [PFQuery queryWithClassName:@"user"]; //1
[query whereKey:@"email" equalTo:_labelEmail.text];//2
[query findObjectsInBackgroundWithBlock:^(NSArray *userData, NSError *error) {//4
if (!error) {
NSLog(@"%@", usuario);
} else {
NSString *errorString = [[error userInfo] objectForKey:@"error"];
NSLog(@"Error: %@", errorString);
}
}];
I know userData
is an array not a dictionary but then how can I retrieve only the information I want? I did try to pull the userData
as a dictionary instead of an array but the query does not let me do that.
What I want to do is something like:
NSLog(@"%@", userData["name"])
Upvotes: 1
Views: 165
Reputation: 6211
First I would check if your returned array is empty. If it is then no matter what you do you are not going to get the information you need out of the query.
If you are getting an error you should probably think about your query class. You are trying to query on the class "user" whereas I'm guessing you would like to query the built in _User class. To do that you would use a different kind of query:
PFQuery *query = [PFUser query];
Try this query type that Parse gives for this exact purpose and see if your returned data has any valid data. If it does you can either use:
PFUser *user = [userData objectAtIndex:0];
if you know that there should be only one user object returned to you, or you can use:
for(PFUser *user in userData)
{
//Do something with the user object that got returned to you
}
Upvotes: 1