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

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,018 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,018 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,018 Points

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