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 Using Parse.com as a Backend and Adding Users Logging In and Logging Out

Objective-C Block Help

Can someone please explain why this line of code doesn't work for step #3? Thanks!

[PFUser logInWithUsernameInBackground:"@test" password:@"test"  block:(^loginHandler)(PFUser *user, NSError *error)];

2 Answers

I have submitted this exact answer and it still claims it is wrong. I had submitted this answer and thought it was just me doing something off, but now, I am lost!

I'll include the provided TreeHouse code below, along with my answer:


#import "LoginViewController.h"
#import "UIAlertView.h"
#import <Parse/Parse.h>

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)login:(id)sender {
    // This is an example of how to declare a block named loginHandler. It starts with a
    // return type, then the name of the block with a special syntax for naming. The next
    // set of parentheses hold the parameters and their types. Then assigning the block 
    // on the right side looks just like how we defined it in the video (carat with the
    // same parameters in parentheses).
    void (^loginHandler)(PFUser *user, NSError *error) = ^(PFUser *user, NSError *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!"
                                                                message:@"Error logging in."
                                                               delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
        else {
            [PFUser navigationController popToRootViewControllerAnimated:YES];
        }
    };

    // Add your code below!

    [PFUser logInWithUsernameInBackground:@"test" password:@"test" block:loginHandler];
}

@end
Stone Preston
Stone Preston
42,016 Points

The challenge states:Use @"test" as the 1st and 2nd parameters. Then pass in loginHandler as the 3rd parameter.

all you have to do is pass in the name of the block

[PFUser logInWithUsernameInBackground:@"test" password: @"test" block:loginHandler];