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 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

Alphonso Sensley II
Alphonso Sensley II
8,514 Points

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,118 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!