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

Arrays and Ints

so I'm having some trouble with the concatenating part of the task in the array of ints

arrays.swift
// Enter your code below
var arrayOfInts = [1,2,3,4,5,6] 
arrayOfInts.append(7)
var arrayOfInts = arrayOfInts + 8
Giorgos Karyofyllis
Giorgos Karyofyllis
21,276 Points

Hi Kevin, Because you concatenate two arrays you have to include to arrays. The 8 is an integer so put the 8 inside square brackets and it would be fine!

1 Answer

Xiao Huang
Xiao Huang
5,754 Points
arrayOfInts.append(7)

-> ([Int]).append(Int)
This is correct adding an Int to [Int]

var arrayOfInts = arrayOfInts + 8

-> [Int] = [Int] + Int
But here cannot concatenate a [Int] with an Int

arrayOfInts = arrayOfInts + [8]

This could work