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 Basics (retired) Collections Modifying an Array

The answer in this challenge is not correct. Index location for "Deploy App" is 2 not 1. Only accepts 1. Pls correct.

I checked this on Xcode.

arrays.swift
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo += ["Debug App","Fix Bugs"]
todo.removeAtIndex(1)
let item = todo.removeAtIndex(1)

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Greg,

As explained in the video the removeAtIndex method removes the given value index from the Array therefore we can't call it twice as we would be removing the values Build App and Deploy App, instead you just need to call it once and use the index number of 2 since Deploy App is the 3rd item in the array.

var todo = ["Learn Swift", "Build App", "Deploy App"]
todo += ["Debug App","Fix Bugs"]
let item = todo.removeAtIndex(2)

Happy coding!

Thanks Chris! I see that now. This and the next challenge had me so confused. Then I realized I was removing the value twice and thought, "I'm and idiot." That's why the call it learning, huh. Thanks again.

Chris Shaw
Chris Shaw
26,676 Points

You're welcome.

That's why the call it learning, huh.

Indeed, the learning process never ends.