Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Self-Destructing Message iPhone App Using Parse.com as a Backend and Adding Users Signing Up New Users: Part 2 (PFUser)

Signing Up New Users: Part 2 (PFUser)

Challenge Task 1 of 4

In our view controller below we want to sign up new users for our app. In the signup method, start by capturing the username and password from two UITextField properties: 'usernameField' and 'passwordField'. Store the values in the properties 'username' and 'password'.

My code:

import "SignupViewController.h"

import <Parse/Parse.h>

@implementation SignupViewController

  • (IBAction)signup:(id)sender { NSString *username = [self.usernameField.text]; NSString *password = [self.passwordField.text];

}

@end

Result:

Bummer! Compilation Error! Don't forget to use 'self' when accessing properties, and make sure the rest of your syntax is correct!

10 Answers

Andres Oliva
Andres Oliva
7,810 Points

Hahahahaha!

This lines of code:

[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {}];

NSLog("%d",1) }

Should be this:

[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(@"%@", succeeded);
}];
Andres Oliva
Andres Oliva
7,810 Points

You shouldn't write those square brackets.

Try this:

NSString *username = self.usernameField.text;
NSString *password = self.passwordField.text;
Andres Oliva
Andres Oliva
7,810 Points

Ok, I took a look at the challenge. It says that username and password are properties, so you need to access them as properties of your class, not as local variables.

This should work:

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

@implementation SignupViewController

- (IBAction)signup:(id)sender {
    self.username = self.usernameField.text;
    self.password = self.passwordField.text;
}

@end
Andres Oliva
Andres Oliva
7,810 Points

You need to read the challenges more carefully.

You need to initialize the newUser variable using the "user" class method. You are somehow using a "newUser" method. Also, you need to access username and password as properties (as stated) not as local variables.

Try this:

- (IBAction)signup:(id)sender {
self.username = self.usernameField.text;
self.password = self.passwordField.text;
PFUser *newUser = [PFUser user]; 
newUser.username = self.username; 
newUser.password = self.password; 
}

I also noticed that you put an extra curly brace "}" in your code.

Be more careful! In the real development life, these would be errors, and your code wouldn't compile. Just like is happening with the code challenges :/

Andres Oliva
Andres Oliva
7,810 Points

Hahahaha.

You are almost correct. You forgot the square brackets this time. This should be the line of code:

[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {}];

Hi Andres. I tried the your code as below:

import "SignupViewController.h"

import <Parse/Parse.h>

@implementation SignupViewController

  • (IBAction)signup:(id)sender { NSString *username = self.usernameField.text; NSString *password = self.passwordField.text; }

@end

Then got another error result:

Bummer! Make sure you set both the 'username' and 'password' properties!

Any other suggestions?

Thanks!

Can you take a look at my second code for challenge 2?

Challenge Task 2 of 4

Next, create a new PFUser variable named 'newUser' and initialize it using the 'user' class method from PFUser. Set the 'username' and 'password' properties of this user using the properties you just set.

My code:

import "SignupViewController.h"

import <Parse/Parse.h>

@implementation SignupViewController

  • (IBAction)signup:(id)sender { self.username = self.usernameField.text; self.password = self.passwordField.text; } PFUser *newUser = [PFUser newUser]; newUser.username = username; newUser.password = password; } @end

Result:

Bummer! Compilation Error! Make sure you are correctly initializing the 'newUser' variable, and check your syntax.

Haha. Thanks for the heads up. Right on cue, still stuck on #3 now

Challenge Task 3 of 4

Now let's use the 'signUpInBackgroundWithBlock' method to sign up this new user. Send this message to the newUser variable. For the block parameter, copy and paste the following empty block: ^(BOOL succeeded, NSError *error) {}

My code:

newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {}

Result:

Bummer! Compilation Error! Block syntax can be tricky! Copy and paste the empty block from the instructions and check the rest of your syntax.

Hi Andres! So you knew this was coming right? Might as well finish the whole challenge why don't you?

hallenge Task 4 of 4

For now, inside the block, simply log the 'succeeded' parameter using NSLog. BOOL values are really just int values (0 or 1), so you can use the int format specifier: %d. Remember: format specifiers are placed in between the double quotes of an NSString literal, and then the values to be plugged in are specified after the NSString, separated by commas.

My code:

import "SignupViewController.h"

import <Parse/Parse.h>

@implementation SignupViewController

  • (IBAction)signup:(id)sender { self.username = self.usernameField.text; self.password = self.passwordField.text;

PFUser *newUser = [PFUser user]; newUser.username = self.username; newUser.password = self.password;

[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {}];

NSLog("%d",1) }

@end

Result:

Bummer! Compilation Error! Check your syntax! Follow the instructions carefully.

Thanks bud. Appreciate it. This part definitely was a challenge

I agree - it was SUPER challenging.