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?

Help with dictionary challenge

What am i doing wrong with this code? I can get this code to work in Xcode, but not here. Help please!!

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

Compiler Text: swift_lint.swift:5:18: error: immutable value of type '[String : String]' only has mutating members named 'removeValueForKey' let ukCurrency = currencies.removeValueForKey ("UK")

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

let ukCurrency = currencies.removeValueForKey ("UK")

5 Answers

Kenneth Giorno
Kenneth Giorno
4,043 Points

Alright, so the key here is in the compiler error text you get. I'm not entirely certain, because I'm just learning swift, but with some experience in searching error logs, I'd say the swift:_lint.swift:5:18: error: immutable value of type '[String : String]' only has mutating members... translates to

error output: swift line 5 (let ukCurrency = currencies...) character 18 (c in currencies) throws the error... then the first word it says is immutable. we're trying to adjust currencies by calling removeValueForKey on it, but for some reason, perhaps in the code above, currencies can not be changed (or is immutable).

Matthew Jobraal
Matthew Jobraal
429 Points

I'm having the same problem...Help!

Kenneth Giorno
Kenneth Giorno
4,043 Points

Did you check your code for why currencies is immutable/unchangeable?

How can I d this exercise???

How can I d this exercise???

Matthew Jobraal
Matthew Jobraal
429 Points

I'm new to this, but what if you try the following: var currencies = ["US":"Dollar", "UK":"Pound","JP":"Yen"] let ukCurrency = currencies.removeValueForKey ("UK")