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

How do you retrieve any item and then assign to a constant?

I don't the syntax for retrieving a piece of the array and then assigning it to the variable

arrays.swift
// Enter your code below
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(2)
arrayOfInts = arrayOfInts + [9]
let r = arrayOfInts.removeAtIndex(2)

1 Answer

Nathan Tallack
Nathan Tallack
22,160 Points

Good work so far.

You are going to want to use something like this:

let value = arrayOfInts[5]

What we are doing here is making a constent called value (that's what the let does) and giving it the value of what is stored at index 5 from your array (which will be the Integer 6 because your index counts from 0).

Keep up the great work. :)