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

What is the part that I am missing for the ukCurrency constant coding

I was just want to write the code

can you post what you have tried so far

let currencies = [ "US": "Dollar", "UK": "Pound", "JP": "Yen" ] let ukCurrency = currencies.removeValueForKey ("UK")

4 Answers

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

you can access values for keys in dictionaries by using subscript syntax which means placing the key in between brackets after the name of the dictionary:

let someValue = someDict["someKey"] // returns the value for the key of "someKey" in someDict

you need to access the value in the currencies dict with a key of "UK".

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

let ukCurrency = currencies["UK"] // ukCurrency now has a value of "Pound"

see the Swift eBook for more information on accessing and modifying dictionaries

ok thank you but why does adding the comment at the end allow it to work im just want to know for future reference

comments are ignored by the compiler. they are not treated as "code" they are just there for the reader/writer of the code to reference.

so the fact that u recalled the constant on the second part is what made the difference then right

yes

let ukCurrency = currencies["UK"] 

basically says "give me the value from the currencies dictionary that has a key of "UK" and it returns "Pound" and that gets assigned to the constant ukCurrency

ok I follow you thank you Im still trying to get the hang of everything

no problem