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

Insert a new item titled "Learn iOS" at the second position of the 'todo' array

So far in the array it looks something like this ["Learn Swift","Debug App","Fix Bugs"]

my job now is to insert Learn iOS

this is how my code looks insert("Learn iOS", AtIndex::(1)

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

1 Answer

Your code to insert "Learn iOS" as the second element is correct. What error are you seeing?

The code for the stage before looks wrong, though ... my attempt at this looked like:

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

Maybe because i forgot to specify "todo,insert", instead of just insert("")

Good spot! Yes - that would do it!!

Steve.