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?

My code could not be compiled

My code could not be compiled and i don't know why. Can anyone show me what is wrong ?

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

1 Answer

Hi Mathis,

WHat are you being asked to do here?

One question asks you to set up a variable called ukCurrency.

That would be near to what you have:

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

You've got a removeValueForKey: in there which deletes things. That's why I asked what it is you are trying to do.

Steve.

Hi there Steve, This is what they ask: Assign the value for key "UK" to a constant named ukCurrency. But it is right what you said, even doh you didn't know the question. Thank you for your help!

Cool - that's what I put above.

First, the dictionary called currencies is created with the key/value pairs for three countries.

Then, ukCurrency is defined as a constant and assigned the value relating to the key "UK". That looks like:

let ukCurrency = currencies["UK"]

I hope that helps!

Steve.