Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Collections and Control Flow Introduction to Collections Working With Arrays

Eli Hartnett
Eli Hartnett
313 Points

I think the check work button is messed up. I tested in xcode what I think the question is asking, but still wrong.

I got everything correct until the last line which is to remove the 6th item in arrayOfInts and assign it to a constant named discarded value.

// Enter your code below
var arrayOfInts = [1,2,3,4,5,6]
var randomArray = [7]
arrayOfInts += randomArray
let discardedValue = arrayOfInts.remove(at: 5)

1 Answer

Jason Ernsdorff
Jason Ernsdorff
3,112 Points

I’m not sure what problem you are having but it appears that .remove takes the value from the specified slot +1. So .remove(at: 5) removes the sixth slot as you expected. This works perfectly in the latest version of Xcode and in playgrounds discarded value returns 6. If this is not what you are expecting then I guess I don’t understand your question. You know array keys start with position 0 not 1 right?