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?

Malthe Pedersen
Malthe Pedersen
2,338 Points

It really frustrates me, that I am not able to do this!!!!!!!!!!!!!!!! I do not understand your errors!

I cannot assign the value of UK to a constant named ukCurrency....................

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

3 Answers

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

This is the correct answer for the challenge.

Rob Watts
Rob Watts
2,739 Points

You almost had this right: your initial array, currencies, was declared as a constant. Constants are not mutable, therefore you cannot use the removeValueForKey method. Change your "let" to "var" and it will work.

Malthe Pedersen
Malthe Pedersen
2,338 Points

Unfortunaly not, I already tried that, then it says something about, that it needs to be a constant not a variable

Rob Watts
Rob Watts
2,739 Points

Really? Take a look at this screenshot. It's working in my playground: https://dl.dropboxusercontent.com/u/526349/swift.png