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

Code Challenge: Adding the Edit Friends Screen (2 of 3)

I have been struggling with this one for about a day now, and i simply can't figure it out.

The problem is as follows: "Now send the 'findObjectsInBackgroundWithBlock' message to the 'query' variable. Use the code that is commented out as the basics for the block you pass in."

This is what i have so far. The problem (i think) is in the else statement. I simply have no idea how to make this work. Please hint me in the right direction. Thanks.

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

    @implementation AppsViewController

    - (void)viewDidLoad {
        [super viewDidLoad];

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


        [query findObjectsInBackgroundWithBlock^(NSArray *objects, NSError *error) {
            if (error) {
                NSLog(@"Error: %@ %@", error, [error userInfo]);
            }
            else {


            }
        }];

    }

    @end

2 Answers

Hi Jonas,

From the look of it you missed out the ':' after 'findObjectsInBackgroundWithBlock'.

So it should look like this -

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {

        }
    }];

Haha, seriously :) Thank you Michael.

I must admit, i was doing this late at night - thank you for your help!

I am so confused i tried it with - PFQuery *query = [PFQuery queryWIthClassName@"Apps"]; and this does not work in the code,

but this does work below [PFQuery queryWithClassName:@"Apps"] which is weird.

my code for the second part is below and doesn't work I need help please!

import "AppsViewController.h"

import <Parse/Parse.h>

@implementation AppsViewController

  • (void)viewDidLoad { [super viewDidLoad];

    [PFQuery queryWithClassName:@"Apps"];
    

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (error) { NSLog(@"Error: %@ %@", error, [error userInfo]); } else {

    }
    

    }]; }

@end

Try this:

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

@implementation AppsViewController

- (void)viewDidLoad {
    [super viewDidLoad];


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

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)  {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {

        }
    }];
}

@end

Try this:

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

@implementation AppsViewController

- (void)viewDidLoad {
    [super viewDidLoad];


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

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)  {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {

        }
    }];
}

@end