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

Osiris Maldonado
Osiris Maldonado
699 Points

Can an array of items be added with the .append function?

I know that an array of new items can be appended using the +=

todo += ["Additional Stuff", "More Stuff"]

But can an array be added using .append? or can .append achieve just single elements?

Thanks in advance!

2 Answers

The .append call is expecting a single element. If you have an array of strings and try to .append another array of strings you'll get, '[String]' is not convertible to String

Osiris Maldonado
Osiris Maldonado
699 Points

Ok, I see, so .append is only useful for adding single elements. I assume that to add multiple elements, the best bet is to use '+=' ?

I guess so, yes. Or you could use a for loop to iterate through the second array and append each element one by one, perhaps?