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 Collections and Control Flow Introduction to Collections Working With Arrays

Since the array is mutable, let's add two more values to the existing array. There are two ways we can add items to an a

Since the array is mutable, let's add two more values to the existing array. There are two ways we can add items to an array and I want you to give both a try. First, add one item to the array using the append method.

Remember: We invoke methods on an array using a period or dot. After the dot we write out the method name and a value to append in parentheses following the name.

Next, add another item to the array by concatenating an array. When concatenating, assign the results of the expression back to arrayOfInts.

array.swift
var arrayOfInts = (1,2,3,4,5,6)
arrayOfInts.append(7)
arrayOfInts.append(8)
arrayOfInts + (7) + (8)

4 Answers

The wording of the question is really confusing. It turns out it just wants you to add one int for the append and one int for the concatenation

var arrayOfInts = [1,2,3,4,5,6]

arrayOfInts.append(7)

arrayOfInts += [8]

Moritz Lang

this works. Xcode places the values of () in the code when you blow the auto function to work. var arrayOfInts = [1, 2, 3, 4, 5, 6] arrayOfInts.append(7) arrayOfInts += [8]

Moritz Lang
Moritz Lang
25,909 Points

Hey, you should rewatch the video. In Swift you declare an array with [] and not (). Also concatinating an array means arrayOfInts += [7, 8].

Don't second guess yourselves!

It turns out that they only want one value per added array.

Like such:

arrayOfInts.append(x)

arrayOfInts += [x]