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?

Carlos Henrique Martins
PLUS
Carlos Henrique Martins
Courses Plus Student 1,483 Points

Why is not working?

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

This was supposed to be the right answer but it is not. Why the question is asking me to do this why the right answer should be:

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

Because the second command it will return a value and the first one it cannot be mutable because is a constant

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

1 Answer

Hi Carlos,

All you need to do is remove the .removeValueForKey

And then add replace [] round the "UK" key instead of Parentheses like this.

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

let ukCurrency = currencies["UK"]