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

Pierre Robert
Pierre Robert
5,717 Points

todo.append("Debug App", "Fix Bugs") could not be compiled

I was asked to append 2 elements, and I feel I have followed instructions OK. But I get an error.

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 Pierre,

The append function takes a single string as an argument. If you wish to add multiple strings, you need to add an array. You can either use the += operator for this, or you can use the extend function, both with arrays:

options.swift
todo.extend(["Debug App", "Fix Bugs"])
// OR
todo += ["Debug App", "Fix Bugs"]

Let me know if that makes sense!

Best,

-Greg

Pierre Robert
Pierre Robert
5,717 Points

Thank you, Greg! Your second solution worked perfectly.

Best, Pierre