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)

set username and password challenge

Hey All,

I'm having a bit of trouble with my code challenge. I am supposed to set the 2 properties in the signup method (username and password) to the 2 UITextFields (usernameField and passwordField). With my code below, I get the error: "Make sure you set both the 'username' and 'password' properties!".... Any suggestions? Thanks!

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

@implementation SignupViewController

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

}
@end

2 Answers

Gareth Borcherds
Gareth Borcherds
9,372 Points

Because username and password are already properties, you would need to set them using the self. notation as below.

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

@implementation SignupViewController

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

@end

That is because we probably already set them up as a NSString in the header file using something like

@property (nonatomic, strong) NSString *username;
@property (nonatomic, strong) NSString *username;
Gareth Borcherds
Gareth Borcherds
9,372 Points

Also, I used self.usernameField.text in my answer, but that is the equivalent of what you put [self.usernameField text]

Both of them work fine once you start using the self. instead of declaring a new NSString.

awesome thank you!

Gareth Borcherds
Gareth Borcherds
9,372 Points

Don't forget to mark best answer :)