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 Recap: Arrays

Qamar Ali
Qamar Ali
10,015 Points

An array preserves the order of its elements. I dont understand this question

I mean in an array the elements do not necessarily have to be in an order. For example, var todo = [3,6,10,2,0] I am not sure if I understood this question correctly

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Qamar,

An Array will always maintain its order. If your had [3, 4, 6, 8, 3, 2, 2, 45, 1]. This order will remain the same. The value at position [3] will alway be 8 regardless of how many time you call it. Now, a Dictionary (key: value) pairs do NOT maintain the order they are entered. That is why you use the key to access the value, because there is no guarantee that what was second on the first call will be second on the third call.

I hope that helps to clear it up for you. :)

:dizzy:

Qamar Ali
Qamar Ali
10,015 Points

yes it does. Thank you