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?

Kelly de Vries
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Kelly de Vries
Treehouse Guest Teacher

How do I assign the value for "UK" to a constant called "ukCurrency."

I can't figure out what I'm doing wrong here. I'm supposed to assign the value for "UK" to a new constant called "ukCurrency."

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

3 Answers

Andreaus Perkins
Andreaus Perkins
14,402 Points

Things you should do:

  1. Create a constant called "ukCurrency" using the "let" keyword.
  2. Pass the value to the constant by using it's index...for example... (dictionaryName(indexKey).

I would type out the code for you, but I think this is a good learning oppurtunity.

Good luck!

Alan Johnson
Alan Johnson
7,625 Points

The question is asking you to assign the value, but not necessarily to remove the value from the Dictionary.

Kelly de Vries
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Kelly de Vries
Treehouse Guest Teacher

Thanks Andreaus. I actually had tried it that way first, but couldn't get it to work! Your suggestion helped me know I was doing the right thing, though, so I kept at it and discovered it was a non-thinking error (parentheses instead of brackets!). Thanks for letting me know I was on the right track with my less convoluted option!