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 Build a Self-Destructing Message iPhone App Relating Users in Parse.com Adding the Edit Friends Screen

Ericson Ortega
Ericson Ortega
3,307 Points

Stage 2 iOS self destructing message app challenge stuck

I can't proceed my code and I don't know what is wrong.

here is my code for the challenge:

- (void)viewDidLoad {
    [super viewDidLoad];
    PFQuery *query;
    [PFQuery queryWithClassName:@"Apps"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {
          self.Apps=objects;
        }
    }

}

1 Answer

Stone Preston
Stone Preston
42,016 Points

you almost have it correct, but you have a few errors that are keeping you from passing.

in task 1 you need to assign the return value of the queryWithClassName method to your query. you just declared the query, you never assigned it a value. so fix that:

PFQuery *query = [PFQuery queryWithClassName:@"Apps"];

you need to close the call to findObjectsInBackground with block by adding the closing bracket and semicolon:

 [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {

             self.Apps=objects;

        }
    }]; //close the method

you also forgot to reload the tableView in task 3

else {

             self.Apps=objects;
             //reload the tableView
             [self.tableView reloadData];
        }

so fixing those errors leaves you

#import "AppsViewController.h"
#import <Parse/Parse.h>

@implementation AppsViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //set the query
    PFQuery *query = [PFQuery queryWithClassName:@"Apps"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {

             self.Apps=objects;
             //reload the tableView
             [self.tableView reloadData];
        }
    }]; //close the method
}

@end