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 Basics (retired) Collections What is a Dictionary?

Difference between constant and variable in this context.

I'm wondering if this is a bug, I've posted about it previously but the response solutions do not work in the exercise.

If you try this exercise and create a constant with the dictionary as requested and then go to the next exercise (which builds on this), it simply will not work.

There is a working solution of course - and that is to make the constant a variable (for the dictionary).

Does this work as a constant for anyone?

dictionaries.swift

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

The challenge that you are linking from, I think you may be misunderstanding the 2nd Task. You're not actually building on the constant created in Task one. The challenge wants you create a new constant and assign a value pulled from the dictionary created prior.

So, the completed code for the second task is as follows:

let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]

let ukCurrency = currencies["UK"]

Have a look and see if it makes sense. Task one creates the Dictionary and Task two pulls a value from it using a Key.

:dizzy: