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

Finally, we forgot to add that we need to learn iOS development prior to building an app. Insert a new item titled "Lear

Finally, we forgot to add that we need to learn iOS development prior to building an app. Insert a new item titled "Learn iOS" at the second position in the todo array.

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

2 Answers

hey that problem said " add at second position"

so for that it will be

todo.insert("Learn IOS", atIndex: 1)

it worked for me!

Nick Kohrn
Nick Kohrn
36,935 Points

Jonathan,

Remember that arrays begin with a base index of 0. So, if you have 5 items in your array, your indexes are 0-4. If you have 10 items in the array, the indexes are 0-9.

With that being said, when you call todo.insert("Learn iOS", atIndex: 2), you are actually inserting the string as the third item in the array.

Just change your index to 1 to insert the string into the second index of the array.

Hope this helps!

Nick, this didn't help. Please just give me the answer. I've tried everything.

Nick Kohrn
Nick Kohrn
36,935 Points

Garrett,

Can you post the code that you have tried?