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?

Istvan Burgyan
Istvan Burgyan
509 Points

How can I change a constant? This doesn't make any sense?

The challenge is : Let's create a dictionary that contains the currencies of the various countries along with their country codes. The country code will be the key and the currency the value. Using the following key-value pairs: US : Dollar, UK : Pound, JP : Yen assign them to a constant named currencies.

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

The next challenge states: Assign the value for key "UK" to a constant named ukCurrency.

HOW DO YOU CHANGE A CONSTANT??????? IT DOES NOT MAKE SENSE TO ME?

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

1 Answer

Stone Preston
Stone Preston
42,016 Points

you misinterpreted what the task is asking you to do.

task 2 states: Assign the value for key "UK" to a constant named ukCurrency.

you dont change the value assigned to the key "UK", you assign the value corresponding to that key to a new constant:

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

let ukCurrency = currencies["UK"] // ukCurrency now has a value of "Pound"
// currencies remains unchanged, with a value of [ "US": "Dollar", "UK": "Pound", "JP": "Yen"]

this does not modify the currencies dict at all, you just access a value from it. nothing in the dictionary changes. you are basically saying "give me the value that corresponds to this key, and assign that value to this constant". it doesnt change anything about the constant dictionary itself

Istvan Burgyan
Istvan Burgyan
509 Points

Doh! I get it now. Thank you for taking the time to answer my question.

Stone Preston
Stone Preston
42,016 Points

awesome glad that cleared things up