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?

Var? or Let?

I have a problem with this task, I'm trying to solve it with the video info, but there's used a var, and a here, the task requires a let, so I don't really know how to solve it.

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

let ukCurrency = currencies.removeValueForKey("UK")

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Alejandro,

You're on the right track, and are using the correct assignment let in this case. Just so you know, what's done in the videos in usually not what needs to be done in the challenges. They will change it up, so they know you are learning and not just copying. :) Remember, a variable (var) can be altered later on - a constant (let) cannot.

The error the code above is experiencing for the challenge is that you are calling a method on the constant. The challenge wants you to assign the value from the key "UK" to the constant ukCurrency. You don't need to use a method to do this, you just need to assign using bracket notation.

Below is the corrected code. Have a look, and I hope it will make sense.

let ukCurrency = currencies["UK"]

Keep Coding! :)

:dizzy:

Thank you SO much :) it actually make sense now.