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

Svante Lindström
Svante Lindström
859 Points

Hi, I think I'm doing this right: [...] arrayOfInts.remove(at:5) let discardedValue = arrayOfInts

I don't get syntax error when pasting this in xCode, and the error refers to not removing the right value in the array, but I think it's the right one. Can you please check?

array.swift
var arrayOfInts = [0,1,2,3,4,5]
arrayOfInts.append(6)
arrayOfInts = arrayOfInts + [7]
let value = arrayOfInts[4] 
arrayOfInts.remove(at:5)
let discardedValue = arrayOfInts

2 Answers

Svante Lindström
Svante Lindström
859 Points

OK, solved it. I was missing a blank space in arrayOfInts.remove(at:5) which should have been arrayOfInts.remove(at: 5). Strangely enough this didn't create a syntax error in xCode.

Hey! I did same thing as you did but it gives me error Bummer! You also need to use array concatenation to pass the task! To concatenate two arrays, use the + operator. this is the error! Can you help me? My code is

var arrayOfInts = [0,1,2,3,4,5] arrayOfInts.append(6) arrayOfInts = arrayOfInts + [7] let value = arrayOfInts[4] arrayOfInts.remove(at: 5) let discardedValue = arrayOfInts