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

Lewis Mansbridge
Lewis Mansbridge
1,119 Points

Hi there, i have copied the exact video, but still says its not correct, any ideas ? Thank you

Not working but does on my mac in front of me :(

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

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Lewis,

I haven't watched the video, but that can't be a copy of the code there. The append method only takes a single parameter, so your code would cause an error. Instead, you have to call the method twice, once per string you want to add to the array:

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

Alternatively, you can add arrays together (called concatenation, as with strings), rather than appending individual items:

arrayConcatenation.swift
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo += ["Debug App", "Fix Bugs"]

Both of these work - up to you which one you choose!

Happy coding! :thumbsup:

-Greg

Lewis Mansbridge
Lewis Mansbridge
1,119 Points

That worked thank you so much!!!!!

Greg Kaleka
Greg Kaleka
39,021 Points

Lewis, one other point: you should really be taking the Swift 2.0 Basics course, rather than this Swift Basics course. Quite a bit has changed, and you should be learning the latest syntax and rules.

https://teamtreehouse.com/library/swift-20-basics

Lewis Mansbridge
Lewis Mansbridge
1,119 Points

Oh i thought i was on the most recent one Haha thank you very much!!!

Greg Kaleka
Greg Kaleka
39,021 Points

No worries - if you're committed to learning iOS programming, I suggest following the iOS development with Swift 2.0 track.