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

Exploring the Master Detail Template

Challenge # 3

Now make the 'bookTitle' upper case.

My code:

NSCharacterSet *bookTitle = [NSCharacterSet uppercaseLetterCharacterSet, bookTitle];

Result:

Bummer! You need to call a method on the instance variable 'bookTitle'.

Is it me, or all three challenges were not shown / discussed in the previous video??? I don't see where this challenge came from!

9 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Joey,

This example would have come from the iOS basics course, the code you have above won't work as the task is asking for NSString while you're trying to set a type of NSCharacterSet for bookTitle, the simplest way to transform a string into all caps is by calling the uppercaseString method directly on the string itself like the below example which eliminates the need to set the value again and cleans up any clutter in our code.

NSString *bookTitle = [[booksArray objectAtIndex:2] uppercaseString];

Hope that helps =)

Thanks John. However, I got this message next:

Bummer! You need to call a method on the instance variable 'bookTitle'.

Any suggestions?

Chris Shaw
Chris Shaw
26,676 Points

Could you please post the code you're using for the challenge

NSString *bookTitle = [[booksArray objectAtIndex:@"Othello"] uppercaseString];

Chris Shaw
Chris Shaw
26,676 Points

Your above code won't work as you're passing a string literal to objectAtIndex which only accepts an integer or in this case the index of the item you want to select.

In the example I posted above I'm selecting the second index of the booksArray which in reality the 3rd item in the array.

NSString *bookTitle = [[booksArray objectAtIndex:2] uppercaseString]; didn't work either

Chris Shaw
Chris Shaw
26,676 Points

What does your NSArray look like? Could you please post that.

Jacob McLaws
Jacob McLaws
1,497 Points

It worked for me. Thanks John!

Chris Shaw
Chris Shaw
26,676 Points

No problem but who's John? =)

Hi Chris,

Here's my first 2 lines of code:

NSArray *booksArray = [NSArray arrayWithObjects:@"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil];

NSString *bookTitle = booksArray[2];

Chris Shaw
Chris Shaw
26,676 Points

Hi Joey,

I just tried the following and had no problem passing the task, based on the above code you will continue to get an error message as your're not converting the string to uppercase.

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

Also because this is an intermediate course I would recommend creating the NSArray using a literal which is easier to work with and read.

NSArray *booksArray = @[@"Hamlet", @"King Lear", @"Othello", @"Macbeth"];

I'm sorry but that still doesn't work...

NSString *bookTitle = [[booksArray objectAtIndex:2] uppercaseString];

Bummer! You need to call a method on the instance variable 'bookTitle'.

Chris Shaw
Chris Shaw
26,676 Points

Which task is it failing on as I just tried it again with no problems occurring. Also during the challenge could you please take a screenshot of each task up until the one that fails as the code I posted previously works flawlessly for me.

How do I show you the screenshots? I can't paste them here

Chris Shaw
Chris Shaw
26,676 Points

You can upload them to a service such as imgur and paste the share links.

Do you have a treehouse email add instead?

Chris Shaw
Chris Shaw
26,676 Points

Hi Joey,

It appears you got this solved in another thread https://teamtreehouse.com/forum/master-detail, in the context of the original question the first answer I gave did solve the issue but I think you confused what I initially said with what you were doing.

So it doesn't completely get lost in translation let's break it down.

  • Task 1 asks for an NSArray with the specified values.
NSArray *booksArray = @[@"Hamlet", @"King Lear", @"Othello", @"Macbeth"];
  • Task 2 then asks you to select the second index from the array and assign it to bookTitle
NSString *bookTitle = [booksArray objectAtIndex:2];
// OR
NSString *bookTitle = booksArray[2];
  • Task 3 then asks you to convert the string to uppercase which my answer was simply supposed to go over the top of what you already had resulting in.
NSArray *booksArray = @[@"Hamlet", @"King Lear", @"Othello", @"Macbeth"];
NSString *bookTitle = [[booksArray objectAtIndex:2] uppercaseString];

I'm sorry for any confusion but given this was an intermediate course I didn't see a need to show the full code example, again sorry for any confusion.