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?

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