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

kevin nadjarian
kevin nadjarian
1,498 Points

Order of ARAY

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

How come the correct answer todo.removeAtIndex(1) is "1" and not "2" (for removing Deploy App) (1) shouldn't be Build App instead?

Second question why todo.insert("Learn iOS", atIndex: 1) as is insert Learn iOS as the second position as asked....

2 Answers

Jason Lysinger
Jason Lysinger
8,106 Points

The answer to your first question is because when you declared:

todo.removeAtIndex(1)```
You removed the entry "Build App" from the array.
So when you then declared:
```let item = todo.removeAtIndex(1)```
You removed "Deploy App" from the array and store it in the constant "item".

You can do away with the first ```todo.removeAtIndex(1)```

I don't quite understand your second question.