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

Mike NZ
Mike NZ
2,415 Points

todo.append doesn't work?

When getting to the question that asks to append "Debug App" and "Fix Bugs" to the todo array, I write my code as follows:

todo.append("Debug App", "Fix Bugs")

It comes up with an error, and when checking with the Preview, it just has a pointer to the first parenthesis. I'm confused because this was how it was taught in the video, and after doing a test array in Xcode, it works completely fine.

I have also typed todo after my line of code for it to print the new array, but the error still occurs.

Is there something obvious that I'm missing?

1 Answer

Robert Bojor
PLUS
Robert Bojor
Courses Plus Student 29,439 Points

Hi Mike,

If you check the documentation on the .append method you will notice that it only accepts one parameter. So todo.append("Element") will work.

If you want to append two or more elements to your array, you can use

todo += ["Element 1", "Element 2"....etc]
Mike NZ
Mike NZ
2,415 Points

Thanks Robert. This saved a lot of confusion!