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?

aidan cheifetz
aidan cheifetz
797 Points

I'm doing everything same as in the video, but it won"t work.

i've tried many times and it's not working. I even tried doing it in the actual swift program and it doesn't work there either.

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

2 Answers

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

You cannot remove objects from an array assigned to a constant, as it is immutable. If you wanted to do that, it had to be mutable, that is a variable instead of a constant. Have a look at the compiler error message, it will tell you just that.

Nevertheless, the task is described as follows

Assign the value for key "UK" to a constant named ukCurrency.

So there is no need to remove the UK currency from the original currencies array. Just assign it to the ukCurrency constant and it should be fine.

let currencies = ["US" : "Dollar", "UK" : "Pound", "JP" : "Yen"]
let ukCurrency = currencies["UK"]
aidan cheifetz
aidan cheifetz
797 Points

thank you so much! Sorry for the trouble I'm pretty new to this.

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

You are welcome! No worries, that's what this forum is for. Keep on learning and you will be the one answering questions :)