Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Basics (retired) Collections What is a Dictionary?

Andriy Yezerskiy
Andriy Yezerskiy
1,808 Points

Hello It came to my attention that this exercise is broken, as you cannot removeValueForKey from a constant.

// it has to be:

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

let ukCurrency = currencies.removeValueForKey("UK")

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

5 Answers

Hi,

Apologies for my previous answer - I hadn't read the code challenge!!

I don't think you're removing anything from the constant called currencies. You create the dictionary, then assign the value of currencies["UK"] to a constant called ukCurrency. There's no removing of anything from the immutable dictionary.

Steve.

let currencies = ["US" : "Dollar", "UK" : "Pound", "JP" : "Yen"]
let ukCurrency = currencies["UK"]
Andriy Yezerskiy
Andriy Yezerskiy
1,808 Points

Yes i am aware of that, I just found a solution to this problem. Instead of removing value which can't be done when dictionary is a constant. You can add value by doing this:

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

Then the question can be completed :) But thanks for your help

Andriy Yezerskiy
Andriy Yezerskiy
1,808 Points

Thanks for your quick reply :)

Exactly, yes. The question didn't want to remove anything from the dictionary; just assign a value from it to a constant.

Hope you're enjoying the course!

Steve.

Andriy Yezerskiy
Andriy Yezerskiy
1,808 Points

Thanks a lot for your help :) I sure will.

Andriy