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 2.0 Collections and Control Flow Introduction to Collections Working with Arrays

Very confused about concatenating two arrays.

So, I'm asked to concatenate two arrays. I remember concatenation from an earlier course, but the instructions did not ask me to make a second array. Assuming they must have just assumed I would do so to pass the task, I created a second array. When I try to concatenate the two now, however, I'm no longer passing Task One.

I don't know. Perhaps someone can weigh in here.

I assumed by the "two methods to add items to arrays", they meant using the insert method. Instead, they are having me use concatenation. An excellent way to have me use past skills already learned, and I'm glad they force you to recall past information (I've kept all my playground work organized, with personal notes in the form of comments in case I ever forget anything), but the instructions could be a bit clearer. Thanks in advance, everyone! I want to learn this stuff.

// Enter your code below
var arrayOfInts: [Int] = [1, 2, 3, 4, 5, 6]
var arrayOfIntsSecond: [Int] = [8, 9, 10, 11, 12]
arrayOfInts = arrayOfInts + arrayOfIntsSecond

1 Answer

Michael Reining
Michael Reining
10,101 Points

Hi Cohen,

Here is why your code does not work. The code challenge says:

Add another item to the array by concatenating an array.

In other words, they want you to add 1 item only using this method. Not an array with multiple items. ;)

// Enter your code below
var arrayOfInts = [1,2,3,4,5,6]
var arrayOfMoreInts = [8] // add just 1 item not multiple
arrayOfInts = arrayOfInts + arrayOfMoreInts

I hope that helps,


PS: If you found the above helpful, be sure to check out my app which breaks code challenges down and really explains things so you can learn faster.

Code! Learn how to program with Swift


PPS: I could not have developed the above app without going through the awesome resources on Team Treehouse. Stick with it. It is so worth it!

Hi, Michael!

I apologize for the delayed response, my power went out - terrible timing. Thank you so much for your immensely helpful response - I will absolutely take you up on that offer to check out your app. So far, the code challenges have been nice, if a bit easy, challenges, but every now and then I hit that little stumbling block - an app that helps with that will certainly be useful.

Thanks again! Marked your answer as best answer.