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?

if i says that currencies [UK] = "ukCurrency" is my code is wrong ??? to assign the value for UK??

well there are different way to assign values i have two style to assign the value currencies [UK] = "ukCurrency" it showing me error in treehouse platform but work in my compiler and the other style is let ukCurrency = ["UK": "ukCurrency"] but that code will not update the currencies Dictionary.

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

1 Answer

Hiya,

I don't know if this should be a constant or a variable assignment (I'll assume constant), however, the code should look something like:

let ukCurrency = currencies["UK"]

Don't rely on Xcode not throwing an error to confirm your code is correct - Xcode doesn't know what you are trying to solve.

Steve.