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?

Josh Smith
Josh Smith
1,049 Points

I don't know why I'm not assigning the value of UK currency to it's new constant ukCurrency correctly

I've tried 10s of combinations getting the value of UK into it's new constant of ukCurrency but I'm not cracking it...?

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

currencies["UK"] = ukCurrency

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Josh:

Think right to left when coding, or at least thatโ€™s how I see it and it helps me. For example

/*
When you are declaring a constant or a variable and then giving it a value
it looks something like this.
*/

var someVariable = "Value"


// so look at it this way.
//   Holds Value  <---- Value

var someVariable = "Value"

// Now someVariable is holding the value

Now in your challenge. currencies[โ€œUKโ€] returns a value, and we want to assign that value to a constant.

/*
 Here we are declaring a constant named โ€œukCurrencyโ€
 and giving it the โ€œUKโ€ value, which in this case is โ€œPoundโ€, because
 thatโ€™s what the dictionary returns from the key โ€œUKโ€. 
*/

let ukCurrency = currencies["UK"]

I hope this crazy explanation helps you a bit. I learn in a visual manner, so I have to see things in a different way lol.

Josh Smith
Josh Smith
1,049 Points

Dude thanks so much Jhoan! Really appreciate you taking the time to do lay it all out for me like that. I was trying so many different combinations in the end, I got close haha but obviously didn't get the nail!

Thanks man :D