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 am i doing wrong?

whats wrong with my code and what is the correct why to write it?

arrays.swift
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo += ["Debug App", "Fix Bugs"]
todo.remove[2]
 let item = "Deploy App"
James Tench
James Tench
43,891 Points

What is the problem asking you to do?

1 Answer

Richard Lu
Richard Lu
20,185 Points

Hey Brandon,

I'm not sure what problem you're getting, but I'll give it a shot. There seems to be two things that are wrong:

  1. Removing an element from a unretrievable location
  2. Method of removing is incorrect

To fix these issue, I've modified your code:

var todo = ["Learn Swift", "Build App", "Deploy App"]

todo += ["Debug App", "Fix Bugs"]
todo.removeAtIndex(4)   // assuming you want to modify the last position in your array

let item = "Deploy App"

I'd recommend another way of removing the last position in your array if that's what you're trying to accomplish.

todo.removeLast()

Hope I've helped. Happy Coding! :)