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 Blog Reader iPhone App Exploring the Master-Detail Template Modifying the Master-Detail Template

changing string's case

in the following code: NSArray *booksArray = [NSArray arrayWithObjects: @"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil]; NSString *bookTitle = [booksArray objectAtIndex: 2];

-(NSString *) uppercaseString{

NSString *msg = [bookTitle uppercaseString];

return msg;

}

I have to make the "bookTitle" uppercase. I have tried a lot of things however it failed to execute. Plz help

2 Answers

Daniel Templin
Daniel Templin
5,293 Points

It took me a little bit on this one too (the documentation wasn't super clear on implementing the uppercaseString method), but after playing around with it a little in Xcode and digesting the syntax a little my code looked like:

NSArray *booksArray = [NSArray alloc] initWithObjects:@"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil]; NSString *bookTitle = [[booksArray objectAtIndex:2] uppercaseString];

Since it's all being called inside a single block of code (from the Apple documentation it looks like normally you'd create a method to return the *bookTitle NSString, and not just directly initialize and modify), you can just use the inner square brackets to get the value from the array and then modify the string with a second method call in the outer brackets. I'm sure someone could probably explain the deeper details of the logic behind it and/or probably provide a slicker solution, I'm considerably more burnt out from my day job today than usual.

Hey Daniel! Thank you so much for the workaround .:)