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 2.0 Collections and Control Flow Dictionaries Working with Dictionaries

Asad Chishty
Asad Chishty
422 Points

How would I assign the value to a constant for applePie?

I tried the following and they didn't work;

let applePie = ["AP"]

iceCream["AP"] = applePie

I'm not understanding how to pull the data from the dictionary and then assign it to a constant. When I try the first one, let applePie = ["AP"] it says to pull the key from the dictionary instead of just assigning it to a string.

dictionary.swift
// Enter your code below

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

  iceCream["RR"] = "Rocky Road"

  iceCream["AP"] =  "applePie"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're supposed to declare a constant and retrieve the value from the dictionary. Take a look:

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

  iceCream["RR"] = "Rocky Road"
  let applePie = iceCream["AP"]

Here we update our dictionary to include the "Rocky Road flavor". Then we declare a constant with let and retrieve that value from iceCream at the key "AP". This will be assigned back into our applePie constant.

Hope this helps! :sparkles: