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

There shows an error when I try to compete the 3rd task in this challenge.

Although in the 3rd task I put todo.insert("Learn iOS", atIndex: 1) it says that todo has the wrong value in it. When I tried using the preview, nothing shows up.

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

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Tiffany.

The problem relates to task 2/3 of the exercise:

That part asks you to remove the third item and assign it to a constant named item. Instead of the 2 lines you wrote:

todo.removeAtIndex(1)
let item = todo.removeAtIndex(1)

You should use this 1-line code:

let item = todo.removeAtIndex(2) 

This is because you actually did what the 2/3 exercise asked (so you managed to pass that challenge) but you removed 2 items (the first at index1) and then the second at the new index 1 after removing the first item. This resulted into a problem with challenge 3/3.

Let me know if it is all clear.

Vittorio