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

David Zakaryan
David Zakaryan
512 Points

Where is my mistake

I don't see my mistake here... also all the other steps were correct, why is this one wrong???

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: 3)

1 Answer

The task wants you to insert the new string at the second position in the array. Because Swift uses 0-based indexing, you're adding it at the fourth position (0 is first, 1 is second, 2 is third, 3 is fourth). So you should use atIndex: 1.

Also, I noticed that you've removed two items from the list in previous step. That's different than what I did, which was to remove one item at index 2. That might also be causing problems with the grading.