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

Bummer code error, not sure why!

Coming back with an error and not sure why that is, any help would be much appreciated :)

arrays.swift
// Enter your code below
var arrayOfInts = [4,5,6,7,8,9,10]
arrayOfInts.append(11,14) 
arrayOfInts += [13]

Hi Patrick,

The code you've written is correct it just they wanted you to add one number for each method. See below -

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

Hope this helps. And keep up the good work!!

Thanks, Michael J

2 Answers

Hi Patrick,

Further to what Michael put, and he's right, the length of the array after the last challenge was expected to be two more than the first task. However, you used the append method with two parameters; Swift won't allow that. You can use += to add an array of any length to another array but the append method can only add one element at a time.

var array = [1, 2, 3]
var anotherArray = [4, 5, 6]
array.append(anotherArray) // fails - can't convert [Int] to Int
array += anotherArray // works fine
array.append(10)   // works fine
array.append(12, 13)  // Fails. Can't use (Int, Int) with append

I hope that helps.

Steve.

oh yeah alright cheers