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

Ibrahim Abdul-Karim
PLUS
Ibrahim Abdul-Karim
Courses Plus Student 296 Points

Array Challenge 3/3

I can't figure out why this is wrong it says the value in my todo variable is wrong. It asks me to insert "Learn iOS" in the second position of the array.

arrays.swift
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: 3)

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Ibrahim Abdul-Karim,

You have a couple of problems which I've mentioned below.

  1. Your first called to removeAtIndex isn't needed as you're not assigning the value to anything
  2. Your second call to removeAtIndex should have a value of 2 as you need to remove the 3rd array value
  3. Your insert call should add the Learn iOS string at index 1 which is the second item in the array
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo += ["Debug App","Fix Bugs"]
let item = todo.removeAtIndex(2)
todo.insert("Learn iOS", atIndex: 1)

Happy coding!