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

What does it mean your 'todo' array has the wrong value in it?

I added to my Array "learn ios" in the second position and its telling me i did it wrong. ex: todo.insert("Learn ios", atIndex: 1)

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

2 Answers

You might just be able to insert a new string to a index which is empty. As I can see in your code your Index[2] might be empty because you called the "removeAtIndex(2)" method. Try to insert it into the Index 2 instead of Index 1 as you did in your Insert Method

Perhaps because it is supposed to be iOS not 'ios'. This is the answer.

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)

Hey Thanks for for your help, I knew i had it right cant believe i didn't see that.