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?

Nikolaos Ntemos
Nikolaos Ntemos
3,271 Points

Is this a bug?

I am trying to complete Task 2 on the Dictionaries Section but i don't now what is the matter with this code:

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

let ukCurrency = currencies

ukCurrency["UK"]

I xcode everything seems fine.

Is this a bug?

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

let ukCurrency = currencies

ukCurrency["UK"]

2 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Your code runs, it's just not accomplishing the outcome that the challenge wants. They want you to put the just value of the UK currency inside the constant ukCurrency. You're putting the whole dictionary (all the currencies) into ukCurrency. Try this:

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

let ukCurrency = currencies["UK"]
Nikolaos Ntemos
Nikolaos Ntemos
3,271 Points

Thank you ! That was the point :-)