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 Signing Up New Users: Part 1 (UIAlertView)

Tommy Choe
Tommy Choe
38,156 Points

Need help understanding syntax for NSString method call 'stringByTrimmingCharactersInSet'

Why is the proper syntax for this method call [self.usernameField.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewLineCharacterSet]]; instead of something like [NSCharacterSet stringByTrimmingCharactersInSet: self.usernameField.text?

I'm not understanding how this works.

P.S. I tried reading the document but I still don't understand why this method call is structured like this.

Michael Metzger
Michael Metzger
11,983 Points
Objective-C

//method one 
NSCharacterSet *input = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:input];

//method two
NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

Both of these syntax achieve the same thing. In method two, you are simply creating the NSCharaterSet instance in the same line. Hope this helps!

1 Answer

Tommy, here is a full template for the social network application: Click Here.