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

Help wanted here please

What went wrong here?

dictionary.swift
// Enter your code below
var iceCream = ["CC": "Chocolate Chip", "AP": "Apple pie", "PB": "Peanut Butter"]

iceCream["RR"] = "Rocky Road"

let applePie ["AP"] = nil

1 Answer

Matt Skelton
Matt Skelton
4,548 Points

Hey Shak,

So here you want to create a new constant named applePie, and assign it a value associated with the key for apple pie within our dictionary. Let's take a look at this process a step at a time, and start by declaring our applePie constant

let applePie

Now we've got our constant, let's revise how we retrieve a value from our dictionary. We need to the subscript notation on our dictionary, inputting our key for apple pie to retrieve its value. This can be done like so:

iceCream["AP"]

However, in order to complete the challenge, we need to assign this value to our new constant. Bearing the two previous considerations in mind, we can combine them into one statement that will do the job:

let applePie = iceCream["AP"]

Hope that helps, keep it up!