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?

Hi, how can I change the value of a constant?

If I try let ukCurrency = currencies.removeValueForKey("UK")

it's not possible because I already have currencies as a constant.

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

2 Answers

Cameron Armstrong
Cameron Armstrong
9,406 Points

Then make it a variable instead of a constant. Constants by definition are... well.. constant. They don't change.

Replace the "let" with "var"

Yeah, I was trying to, but I had to keep currencies as a constant, my approach was incorrect. Instead I use another way to reassign the value from the dictionary.

let ukCurrency = currencies["UK"]

Thanks