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

Please help!!!!

Great job so far! Clearly you know how to add and read items from the array so in this challenge let's try getting rid of a value.

For this task, remove the 6th item from the array and assign the result to a constant named discardedValue.

To remove an item, use the method removeAtIndex() and put the index number in between parentheses that you want to remove.

var arrayOfInts = [1,2,3,4,5,6]

arrayOfInts.append(7)

arrayOfInts += [8]

let value = arrayOfInts.removeAtIndex(5)

let discardedValue = value.count

1 Answer

var arrayOfInts = [1,2,3,4,5,6] arrayOfInts.append(7) arrayOfInts += [8]

Okay, so I am not sure what challenge this came from, so I have no idea whether or not this was already there or it was something you added yourself (meaning I am not sure whether they intended you to remove 6 or 8).

But lets just assume they wanted you to remove 8. In that case because arrays are 0 based, you would have to remove the 7th index.

let discardedValue = arrayOfInts.removeAtIndex(7);

Of course you could be more general about it.

let discardedValue = arrayOfInts.removeAtIndex(arrayOfInts.count - 1);

Thank You now it's cool!!!!