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?

I'm struggling on this code challenge. You can't remove anything from a constant

I created the dictionary as the challenge requested. Now it's wanting me to remove a key and assign it to a new constant. However, you can't edit a constant. Hence my confusion on how to pass this.

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

2 Answers

B B
B B
2,934 Points

I believe it just asks you to assign the UK currency to a constant, so you just need to do a let statement = the dictionary entry for UK currency using the correct syntax.

Dennis Parussini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dennis Parussini
Treehouse Project Reviewer

The actual answer isn't to remove the value from the dictionary, but to assign a given value from the dictionary to a new constant. So the right answer would be

let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies["UK"]
Curtis Curry
Curtis Curry
717 Points

That did not seem to work for me so I tried to do it like this and am still getting an error: Bummer! You need have let ukCurrency defined.

Here is my code:

// Code Country Code // or // Key Value // US Dollar // UK Pound // JP Yen

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

let ukCurrencies = currencies["UK"]

Curtis Curry
Curtis Curry
717 Points

AND apparently I don't know how to post my code and make it look all pretty like you guys. I read the Markdown stuff but it isn't making sense.

Dennis Parussini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dennis Parussini
Treehouse Project Reviewer

@Curtis: You have a typo.

The challenge says you have to assign it to let ukCurrency, not let ukCurrencies.

Curtis Curry
Curtis Curry
717 Points

Oh yeah, I had ukCurrencies and changed it to ukCurrency and it worked. I copied/pasted from your example above. For other users: don't be like me, don't copy and paste! It's a trap! :)

No, but seriously, maybe we can edit the code in your answer above. Thanks for the response!