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 trialthiagobarbosa
1,151 PointsMaking upper case
I can't understand apple`s documentation for upper case. how can I make 'bookTitle' upper case using this:
- (NSString *)uppercaseString
4 Answers
Matthew Mascioni
20,444 PointsSorry to hear that!
uppercaseString is an instance method. If you recall from some of the Treehouse videos, instance methods work on an instance of a given class. So, if I instantiated an NSString named stringy:
NSString *stringy = @"Hello World!";
Then use uppercaseString on the instance of NSString we've created:
[stringy uppercaseString];
... nothing visible happens. uppercaseString is still working, though. However, once it finishes converting the string to uppercase letters, there's no output to console, or anything immediately noticeable. So it cries in a corner for a little bit. But, if we did this:
NSString *stringy = @"Hello world!";
NSString *uppercase = [stringy uppercaseString];
NSLog(@"%@", uppercase);
Or this:
NSString *stringy = @"Hello world!";
NSLog(@"%@", [stringy uppercaseString]);
... Our console will spit out HELLO WORLD!
Hope this helps! Try exploring other instance methods for NSString. You'll find Apple has a lot of neat ones, like enumerateLinguisticTagsInRange.
Matthew Mascioni
20,444 PointsYou're welcome! When we look at:
- (NSString *)uppercaseString;
We see three things. First, our '-' symbol, which tells us that this method is an instance method (which I explained previously). Then, we see (NSString ), which tells us that this method *returns an NSString. Finally, we see 'uppercaseString', which is just the name of the method.
When we write:
NSString *newString = [oldString uppercaseString];
We are running uppercaseString on the oldString. This returns an NSString, as I explained above. We then assign this new string to our newString variable.
thiagobarbosa
1,151 PointsMatthew, thank you very much for you help, but please help me to figure out how can I read :
- (NSString *) uppercaseString and understand: NSString * newString = [oldString uppercaseString]; ? =/
thiagobarbosa
1,151 PointsMatthew, thank you again. This probably will help me to understand apple's documentation. =)
Matthew Mascioni
20,444 PointsAnytime!