Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.