Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Collections and Control Flow Dictionaries in Swift Working With Dictionaries

Stuck in Dictionaries

I'm stuck in the test part of dictionaries. I rewatched the videos and had notes to help me remember the lecture, but i cant seem to get the answer here although i followed what the professor told me to do.

"Let's pretend a customer has ordered an ice cream. Retrieve the value for apple pie using the correct key and assign it to a constant named applePie."

Thanks in advance! :)

dictionary.swift
// Enter your code below

var iceCream = ["CC": "Chocolate Chip", "AP": "Apple Pie", "PB": "Peanut Butter"]

iceCream.updateValue("Rocky Road", forKey: "RR")


iceCream["AP"]
let applePie = iceCream["AP"]

2 Answers

Hi Ronie, I dont think youre as "stuck" as you think you are. You made it to part 3 of the challenge! good job!

Everything is right with you code except where you inserted iceCream["AP"] above the applePie constant. Was there a reason you added this?

I thought that "Retrieve the value for apple pie using the correct key" means reading the dictionary. I tried to delete the iceCream["AP"] but came out as an error. I think it was a bug on the site because i refreshed the page and tried the code without, and it worked.

Thank you so much for answering my question.

Stuart Wright
Stuart Wright
41,101 Points

You just need to delete:

iceCream["AP"]

Your next line is correct.

The line that you're deleting would be fine in Playground if you just want to see what the value of iceCream["AP"] is, but you would never use it in a real program, and it's what causes the following error in the code challenge:

swift_lint.swift:23:9: error: expression resolves to an unused l-value
iceCream["AP"]
~~~~~~~~^~~~~~

I'll remember that! Thanks so much!