Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 :)