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?

Julien Mayer
Julien Mayer
1,880 Points

I have been stuck on this exercise for two days now

, and I can not seem to figure out what I am doing wrong... Any ideas? :)

Thank you so much!

dictionaries.swift
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies.removeValueforKey("UK")
Julien Mayer
Julien Mayer
1,880 Points

by the way, I forgot to mention that the .removeValueforKey should have an uppercase letter for the word "for". This does not change the outcome of my code though... I still get it wrong every time.

2 Answers

Julien,

I think the challenge wants you to get the value from the dictionary of currencies. Each of our currencies are indexed using the counties code. To access the value we just need to reference the key which will then pull up our value.

// Declare our currencies dictionary
let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
// Access the value for the country UK
let ukCurrency = currencies["UK"]

For more information I recommend checking out Apple's official Swift documentation.

Let me know if this is what you were trying to achieve.

Julien Mayer
Julien Mayer
1,880 Points

Thank you so much! that is exactly what I needed!

Julien

Julien Mayer
Julien Mayer
1,880 Points

Thank you so much! that is exactly what I needed!

Julien

Ryan Jin
Ryan Jin
15,337 Points

If the question asks you to delete the value, then you use remove value for key. If not, you don't remove the value. You simply just do this:

let currencies = ["US": "Dollar", "UK": "Pound", "JP": "Yen"]
let ukCurrency = currencies.["UK"]
Julien Mayer
Julien Mayer
1,880 Points

Thank you so much Ryan!

I have now completed the Swift Basics, and I am ready to move on to the next category!

Julien