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 trialJUDY TRAN
709 Pointscannot get the value
I have created a contact ukCurrency and assigned it to UK value. And trying to access to the value....
1 Answer
Jhoan Arango
14,575 PointsHello Judy:
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"]
// With this key, I am getting "Ford Fiesta".
/*
Ok so now let's say that you want to go riding a car.
This is 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("JUDY likes to ride his new \(bmw)")
This will print JUDY likes to ride his new BMW X5.
Hope this explanation helps you understand a bit better and solve your challenge.
Good luck