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

Ben Masel
Ben Masel
2,004 Points

Where do i put the addition operator?

Where do i put the addition operator? i can't figure it out! I just started array's and i don't completely understand.

arrays.swift
// Enter your code below
var arrayOfInts: [Int] = [1,2,3,4,5,6,7]
arrayOfInts.append(8)
arrayOfInts.insert((9),atIndex:8)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! In the first task I believe you were supposed to have 6 elements. It seems you added a seventh by adding it directly into the array. Your second line is spot on, though! :smiley: I'm going to show you how I did it and then explain:

// Enter your code below
var arrayOfInts: [Int] = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts + [8]

Here we have our array which we originally set up, which you obviously did just fine. And then we use the append method on the array to add in the number 7. So far, so good. Now the last line we're concatenating another array to our original array. In reality, that second array could hold just about anything. I picked the number 8 because it makes sense given the example. But it could be arrayOfInts + [8, 2909, 3491]. You would then have an array that looked like this [1, 2, 3, 4, 5, 6, 7, 8, 2909, 3491]. Hope this is helpful! :sparkles: