Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Parse Question: How to retrieve the 'objectId' from an array of objects from PFQuery?

I have provide a part of the code where I am retrieving the array of objects that were created when I ran a PFQuery: - (void)retrieveOrders { PFQuery *orderQuery = [PFQuery queryWithClassName:@"Orders"]; [orderQuery orderByAscending:@"createdAt"];

[orderQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error) {
        NSLog(@"Error %@ %@", error, [error userInfo]);
    }
    else {
        NSLog(@"hmm... %@", [objects objectAtIndex:1]);
        self.ordersArray = objects;
        [self.tableView reloadData];
    }
    if ([self.refreshControl isRefreshing]) {
        [self.refreshControl endRefreshing];
    }
}];

}

I have a NSLog statements that is printing all the objects in the array at index 0.

Below is the NSLog print out and I am trying to extract the orderId object 'TQfc8zxGtU' from this array. Can anyone assist?

Practice[34138:60b] hmm... <Orders:TQfc8zxGtU:(null)> { recepientName = "INDEX 1"; senderName = "INDEX 1"; }

thanks!

1 Answer

I think I answered my own question.....

PFObject *removeObject = [self.ordersArray objectAtIndex:indexPath.row-1];
NSString *deleteID = removeObject.objectId;

Thank you this worked for me :)