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

Jason Hoddinott
Jason Hoddinott
477 Points

You also need to use array concatenation to pass the task! To concatenate two arrays, use the + operator.

I'm starting to get a little annoyed at the Challenges. We learn through the videos how to use Strings to build the Array, but then in the Challenge we have to use Int. Nothing I'm doing is working because I'm getting an error in Xcode "Cannot cal value of non-function type '[Int]'

Why do we learn it one way, and then there's no help when we have to use another method?

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

1 Answer

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

The thing is that by arrayOfInts = arrayOfInts + 8 you are trying to concatenate an array, that is [Int], with an Int. Instead you have add an [Int] to an [Int] instead, that is merging two arrays. The following works:

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

P.S. It does not make a difference it it's an array of Ints or Strings, it could be any Element. The concept does not differ here.

Hope that helps :)