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

philippe godfroy
philippe godfroy
596 Points

Challenge task 2 of 3. I'm stuck. I did: let item = todo.removeAtIndex(3) but this isn't correct. Some help on the answr

Can't find the problem?

arrays.swift
var todo = ["Learn Swift", "Build App", "Deploy App"]

todo += ["Debug App", "Fix Bugs"]

let item = todo.removeAtIndex(3)

let item = ["Deploy App"]

2 Answers

Ian Burres
Ian Burres
250 Points

I'm not sure what the rest of your code looks like (since I haven't used Swift nor do I know what you are working on), but if you want to remove Deploy App, then you need to do: todo.removeAtIndex(2). Remember, arrays start at index 0, and since I just looked it up, I know Swift follows this rule.

Ian Burres
Ian Burres
250 Points

If this does not solve your answer, please be a little more specific. Maybe I can help...maybe I can't, :)

philippe godfroy
philippe godfroy
596 Points

Absolute hero! Thank you, my coding was correct, but the index which I gave "3" had to be "2"! I just forgot the arrays starts at 0... Thank you my friend

Ian Burres
Ian Burres
250 Points

I'm not familiar with Swift, but I am an experienced programmer. When you run the code, is it removing Debug App instead, or is it failing to compile?

Ian Burres
Ian Burres
250 Points

You're welcome.