Khledon
Khledon

Reputation: 183

Parse.com query array

I currently have this query for parse.com:

- (void)viewDidLoad
{
    PFQuery *activityQuery = [PFQuery queryWithClassName:@"Activities"];


    [activityQuery whereKey:@"triathlete" equalTo:[PFUser currentUser]];

    [activityQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            _activityArray = objects;
            NSLog(@"activityArray = %@",_activityArray);

        }
    }];

And it stores all of the data from each each object in my database. My question is how can I get the data from the individual columns rather than everything in one array.

Many Thanks

Upvotes: 0

Views: 192

Answers (2)

savana
savana

Reputation: 221

to get the individual columns from the query result use the following manner

    [activityQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
(if!error){   
 for(PFObject *object in objects){
        // to print individual object one by one
    NSLog(@"%@",object);
    // to retrieve individual column  if the column is string type
    NSLog(@"%@",[object objectForkey:@"yourColumnName"]);

    }
}];

Upvotes: 0

Jorge
Jorge

Reputation: 1532

If I understand your question correctly, you can separate columns in different arrays, inside your block, like this:

[activityQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            NSMutableArray *column1 = [objects valueForKey:@"column1"];
            NSMutableArray *column2 = [objects valueForKey:@"column2"];
            NSMutableArray *column3 = [objects valueForKey:@"column3"];
        }
    }];

Then do whatever you need to do with each Array.

Upvotes: 1

Related Questions