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?

Ryan Anderson
Ryan Anderson
4,610 Points

Dont understand challenge task 2 of 2

show me how to do it

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

let ukCurrency = currencies

3 Answers

Ryan Jin
Ryan Jin
15,337 Points

Like an array, but instead you type in the key, not the index

let ukCurrency = currencies["UK"]
Matthew Wiese
Matthew Wiese
1,659 Points

The answer it is looking for is...

let ukCurrency = currencies["UK"]

But I think the question can also be answered (based on the video) like this...

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

let ukCurrency = currencies.removeValueForKey("UK")

If you use this one, the Teamtreehouse compiler will throw an error. It will not throw an error in xCode however.

Hope this helps!

Your second answer actually will not work because the dictionary currencies is declared as a constant, meaning that the the key-value pairs are immutable. You may capture a value in the dictionary, but you cannot remove or change the key-value pairs as long as the dictionary is declared as a constant. Besides, the challenge clearly asks you to CAPTURE one of the dictionary's values and assign it do a new constant, not MUTATE the original dictionary.

i resolved doing this let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] let ukCurrency = currencies["UK"]