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?

It's not letting me "removeValueForKey" for the constant "currencies". In Xcode, it lets me remove the value if I....

....change it from a constant to a variable. It simply doesn't let me do it if currencies is a constant. I'm not sure what to do about it and there is no way to move forward until I get an answer so please answer quickly! I'm making great progress and want to keep my momentum! Thanks :)

8 Answers

Jason Lysinger
Jason Lysinger
8,106 Points

You can not remove values from constants. That is the point of a constant. If you want to make the dictionary editable, it has to be a variable type.

That's what I was saying - I changed it to a variable in Xcode and everything worked. However, in this course - it doesn't let me change it to a variable. For some reason, the course wants it to still be a constant and therefore gives me an error saying that it needs to be one. I think that it's a glitch in the learning program. Is there any way to fix this?

Hattan Alshbat
Hattan Alshbat
341 Points

I'm having the same problem. Is there we can still progress regardless if they get that fixed or not?

I figured this out - instead of "removeValueForKey", I simply assigned the variable - if that makes sense. So here is a hint - your solution does not include editing your constant array - but rather using your constant array.

Hattan Alshbat
Hattan Alshbat
341 Points

sorry i just figured that i can

// define a new variable and assign it the same value as the constant currencies

var currenciesOne = currencies

// then proceed with

let ukCurrency = currenciesOne.removeValueForKey("UK")

While it is true that in Xcode you can simply go back and change the "let" to a "var" so as to change it from a constant to a variable - that is not what the question is actually asking us to do. It's asking us to use the constant to help define the new constant. Does that make sense? I understand that I'm speaking ambiguously - but it feels SO good to grab something on your own instead of just being told what to do. Hit me back up if you just want the answer.

Hattan Alshbat
Hattan Alshbat
341 Points

Thanks Levi, My method worked and i passed the challenge. I'm sure will find another hurdle soon. Good Luck

Awesome! Good luck to you, as well!