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 Swift 2.0 Collections and Control Flow Introduction to Collections Manipulating an Array

Anthony Lambotte
Anthony Lambotte
354 Points

Problem with code challenge

Hello guys, I would like to know what is wrong with my code because it's starting to make me a bit angry... I'm not sure whether it is a problem with treehouse or a problem with my code:

// Enter your code below var arrayOfInts = [0,1,2,3,4,5] arrayOfInts.append(6) arrayOfInts += [7] let value = arrayOfInts[4] arrayOfInts.removeAtIndex(5) let discardedValue = arrayOfInts

It keeps giving me the error "Make sure you remove the 6th item of the 5th Index!" Which is basically what I did right? I tried everything, even changing the values of Int and nothing worked.

Please help me, I don't know how to pass this challenge.

2 Answers

Moritz Lang
Moritz Lang
25,909 Points

Hi Anthony Lambotte, I think discardedValue should not be initialized with the array. Instead it should hold just one Int (the one that get's discarded). To do so you have to initialize discardedValue with the returned value from arrayOfInts.removeAtIndex(5).

The final code would look like this:

let discardedValue = arrayOfInts.removeAtIndex(5)
Anthony Lambotte
Anthony Lambotte
354 Points

Wow I didn't think of it at all! Thanks a lot for the help, I was completely stuck! :)