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

I watched the videos a couple times what am I missing?

hey can I get some help please?

dictionary.swift
// Enter your code below
var iceCream = ["CC":"Chocolate Chip", "AP": "Apple Pie", "PB": "PeanutButter"]
iceCream.updateValue("Rocky Road", forKey: "RR")
let applePie = ("AP")

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi James,

You're simply setting the value of the constant applePie to the string "AP". You need to use subscripting to index into the dictionary. The very beginning of the video Modifying A Dictionary goes over this. You need to use the name of the dictionary and then square brackets with the key inside, like this:

iceCream["AP"]

The code above will return "Apple Pie", which is what you want to store in the variable applePie.

solution.swift
let applePie = iceCream["AP"]

Make sense?

Cheers :beers:

-Greg