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
Rafael Conde
8,127 PointsCode Challenge: Signing Up New Users Part 2
Hello fellow students and teachers!
I'm having some trouble on the challenge 1 of the Signing Up New Users Part 2.
Here's the question:
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'.
Here's my answer:
#import "SignupViewController.h"
#import <Parse/Parse.h>
@implementation SignupViewController
@property (strong, nonatomic) IBOutlet UITextField *usernameField;
@property (strong, nonatomic) IBOutlet UITextField *passwordField;
- (IBAction)signup:(id)sender {
NSString *username = [self.usernameField.text];
NSString *password = [self.passwordField.text];
}
@end
What am I missing, I really can't pin point the problem, if I know myself it's probably a missing bracket or something :p
Can anyone help me? Thanks ;)
2 Answers
Stone Preston
42,016 Pointswell the code
@property (strong, nonatomic) IBOutlet UITextField *usernameField;
@property (strong, nonatomic) IBOutlet UITextField *passwordField;
does not belong in the .m file, they belong in the .h. I think the question lets you assume they are already defined in the .h
Also, it states you want to store the values of the fields in 2 properties which are already defined.
NSString *username = [self.usernameField.text];
NSString *password = [self.passwordField.text];
the above code is wrong because you assign the values of the fields to two new objects, not the existing properties.
Try using the self.propertyName style of syntax to assign the field values
Rafael Conde
8,127 PointsThat solved it guys, thanks so much.
I had to assume both the usernameField/passwordField and username/password properties were already defined.
Again, thanks ;)
John W
21,558 PointsJohn W
21,558 PointsThere's another syntax error in Rafael's code. Brackets ( [ ] ) in Objective-C are for messages/methods or arrays (if prefixed with the @ character). Hence they should also be removed when accessing the self.usernameField.text and self.passwordField.text properties.