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 trialMollie Roberts
515 PointsWhy isn't my code compiling in Swift Basics, when it is compiling in Xcode?
Can anyone tell me why this code is not compiling in the Swift Basics tutorial? It is compiling in Xcode. The task is: Assign the value of the key UK to a constant named ukCurrency.
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"] let ukCurrency = ["Pound"]
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = ["Pound"]
2 Answers
kjvswift93
13,515 PointsYou are close. What you have done is assign ukCurrency to another array which contains only one value, "Pound". Instead, you need to assign it to just the string "Pound", because that is what the value is for the key UK.
You have two options. The preferred way is this:
let ukCurrency = currencies["UK"]
Or, you can simply write:
let ukCurrency = "Pound"
Mollie Roberts
515 PointsThank you so much, Kyle! Your explanation makes perfect sense.