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

help

Remove the last object from your array

my code:

NSMutableArray *elements = [NSMutableArray array];

elements = [NSMutableArray arrayWithObjects:@"Helium", @"Neon", @"Argon", nil]; [elements removeObjectAtIndex:1];

http://teamtreehouse.com/library/build-a-blog-reader-iphone-app-2/getting-data-from-the-web/mutable-vs-immutable

2 Answers

Hi Lyric,

Try this:

[elements removeLastObject];

Would this work for you?

NSMutableArray *elements = [NSMutableArray array];

    elements = [NSMutableArray arrayWithObjects:@"Helium", @"Neon", @"Argon", nil];

    if ([elements count] > 0){
     [elements removeLastObject];
    }

It appears that the in is missing in your ifin statement, am I wrong?

The if statement is just making sure that the count of objects in elements is greater than 0 before removing the last object.

Therefore I do not believe that an if in is necessary. However, I have not done much Objective C coding recently as I am focusing on Swift... so I may be wrong ;)

The code above does compile and behave as expected in my quick tests.

Okay, good.