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?

Im not sure how else to assign the value of UK to uKCurrency. what should I do?

dictionaries

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Edgar:

In a dictionary you have a key and a value, in order for you to access the value of a dictionary you have to use it's key.

So for example :

// Let's create a dictionary of cars
let cars = ["Key 1":"Ford Fiesta","Key 2":"BMW X5", "Key 3":"Audi S4"]

// Now let's access a car by using it's corresponding key.
cars["Key 1"]

/*
   Ok so now let's say that you want to go riding a car.
   This will be capturing the value of "Key 2" and assigning it to a constant named bmw.
*/

let bmw = cars["Key 2"]

// Now you can use this constant in other places, for example. 
println("Edgar likes to ride his new \(bmw)")

This will print Edgar likes to ride his new BMW X5.

Hope this explanation helps you understand a bit better and solve your challenge.

Good luck