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 is wrong here or is a bug

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: 1)

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Josuel,

You're getting an error because you're removing one too many values from the dictionary. Instead you just want to remove the second index which is Deploy App.

let item = todo.removeAtIndex(2)

i tried that but it let me pass task 2 with the code i already have

Chris Shaw
Chris Shaw
26,676 Points

Task 2 shouldn't have passed as the array would have been missing Build App which is required, however in saying that the only other issue is you have written iOS in all lower-case which the challenge isn't looking for.

let item = todo.removeAtIndex(2)
todo.insert("Learn iOS", atIndex: 1)

I figured it out, the real issue was the first task it should have never let me pass with "+=" I had to append each one separately.

There doesn't seem to be anything wrong with that code. What issue are you having, or what do you think is a bug?

i keep getting the same "wrong value error"

What version of Xcode? Have you quit and restarted Xcode? Tried creating a new, empty Playground?

it was actually in one of the challenges task 3

Sorry Josuel - I should have clued in to this being a code challenge. Chris Upjohn has this one covered I think!

I figured it out, the real issue was the first task it should have never let me pass with "+=" I had to append each one separately.