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 trialMarquett Burton
511 Pointsif item in array is removed, how can that item then be defined in the following line as it shouldn't exist?
It seems to me that it should be impossible to call an item that was previously deleted unless we are referring to the new item that takes its place in the array.
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append ("Debug App")
todo.append ("Fix Bugs")
todo.removeAtIndex (4)
let item = 4
1 Answer
William Li
Courses Plus Student 26,868 PointsYou have to do it in one line; also, your index isn't correct.
let item = todo.removeAtIndex(2)
This way, you remove the 3rd item "Deploy App" from the list and assign it to a constant item.
Marquett Burton
511 PointsMarquett Burton
511 PointsMany thanks! Very helpful