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

Razvan L
Razvan L
463 Points

Hey there! How to solve Challenge Task 2 of 4 from Swift 2.0 Collections and Control Flow? I'm stuck at the end

I can't really understand how to solve the last paragraph of Task 2 of 4 from the mentioned chapter. Could you help me with a hint as to how to spell out in code language this concatenation of arrays? Thanks!

arrays.swift
// Enter your code below

var arrayOfInts = [1, 3, 5, 7, 9, 10] 

2 Answers

Razvan, here you go:

var arrayOfInts = [1, 3, 5, 7, 9, 10] 
arrayOfInts.append(12)
arrayOfInts += [14]

The first way uses a method: append(). The second concatenates two arrays to form one that combines both. Note that arrayOfInts =+ [14] is shorthand for arrayOfInts = arrayOfInts + [14]

Razvan L
Razvan L
463 Points

Thank you! Apparently I didn't concatenate properly. :)