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

Reading arrays in code challenge? How do i do this....Got the rest of it...Please help

How do i get passed the part that says read array from fifth position.Thought i have done this correct. Please let me know what to do or what is correct. Gotta say some of the code challenges are bogus

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

2 Answers

Moritz Lang
Moritz Lang
25,909 Points

Hi, if you want to retrieve an item from a specific index on a specific array, you have to specify the array. Otherwise Swift cannot know from which array you want to get the item at index 4. Your code should look like this:

let value = arrayOfInts[4]

Written like you did above you would actually create a new array containing one value (4) and assign it to a constant named value. :)

thanks