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.

Steve Hunter
57,684 PointsDifficulties assigning TextField values to variables.
Here's the question in the code challenge and my proposed solution which doesn't work. I'm not sure what glaringly obvious mistake I've made!
Any thoughts?
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'.
- (IBAction)signup:(id)sender {
NSString *username = [self.usernameField.text];
NSString *password = [self.passwordField.text];
}
4 Answers

Thomas Nilsen
14,957 PointsI think the question is badly frased, but anyway - here is the solution:
self.username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
self.password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

Thomas Nilsen
14,957 PointsFirst of all, writing it like this:
[self.usernameField.text];
is wrong. Don't do that :)
Here are two ways you can write it as
self.usernameField.text; //like this
[self.usernameField text]; //or this
Now, as for your problems: If your having problems with assigning values, I'd start by checking that your IBOutlets are properly connected. If that doesn't help, let me know :)

Thomas Nilsen
14,957 PointsAh sorry, I didn't see it was a code challenge you had problems with. I'll have a look and have an answer for you shortly :)

Steve Hunter
57,684 PointsBrilliant - thank you! :-)
Steve Hunter
57,684 PointsSteve Hunter
57,684 PointsI took the square brackets out ... same result.