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

John Moron
John Moron
1,658 Points

How do I remove "Deploy App"

I need help.

arrays.swift
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append("Debug App")
todo.append("Fix Bugs")

6 Answers

Dominic Bryan
Dominic Bryan
14,452 Points

let item = todo.removeAtIndex(2)

sorry as I was typing this got posted

John Moron
John Moron
1,658 Points

Thank you Dominic Bryan.

Dominic Bryan
Dominic Bryan
14,452 Points

yes sorry Steve Hunter I didn't mention ti was for a question on a track that wants it in a constant named item. Apologies for confusion

No problem, Dominic Bryan - but remember, you can't alter constants.

Happy coding ... keep it up!

I'm not at my computer, and am no expert, but is there a .removeAtIndex(index) method?

Steve.

John Moron
John Moron
1,658 Points

It said that but I don't know how to write that in?

todo.removeAtIndex(2)

John Moron
John Moron
1,658 Points

ohh like that?!!!

John Moron
John Moron
1,658 Points

so how do I write it actually....?

John Moron
John Moron
1,658 Points

Never mind I typed it wrong....

Dominic Bryan
Dominic Bryan
14,452 Points

haha i was just about to say John, again if you want it ive just done the question and this is the copy and paste:

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

You fixed now? Let us know if we can help with anything else ...

Keep up the coding - it does get easier (and more interesting!!). Swift can do some pretty cool stuff - keep at it!

Steve.