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

modifying dictionaries

Challenge Task 3 of 4

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.

Bummer! Make sure you're assigning the value from the dictionary to a constant named applePie

dictionary.swift

var iceCream = ["CC": "Chocolate Chip",

                "AP": "Apple Pie",

                "PB": "Peanut Butter"]

iceCream["RR"] = "Rocky Road"

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

  var str : String = icecream ["AP"].value 

please can you assist what im doing wrong here

dictionary.swift
var iceCream = ["CC": "Chocolate Chip",
                "AP": "Apple Pie",
                "PB": "Peanut Butter"]
iceCream["RR"] = "Rocky Road"
iceCream.updateValue("Rocky Road", forKey: "RR")
  var str : String = icecream ["AP"].value

Moderator edited: Added markdown so that the code renders properly on the forums.

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

Hi! I've added some markdown to your question so that the code will be more readable for others viewing this question. If you look at the bottom of the "Add an Answer" section of this page, you will find a link to a Markdown Cheatsheet. This will give you tips on how to format your questions/answers/comments in interesting ways and how to properly post code :sparkles:

2 Answers

Sean Pooley
Sean Pooley
4,934 Points

If you just wanted to return the value "Apple Pie" you would use

iceCream["AP"]

The challenge asks that you assign this to a new constant, or 'let' with the name applePie

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

Hi Sean! I've moved your comment to be an answer so that it will be eligible for voting and possible "Best Answer" selection. Thanks for helping out in the Community! :sparkles:

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

Hi there! Sean Pooley is correct. The idea of this step of the challenge is to retrieve the value at the key "AP" and assign it to a constant. We use the let keyword to assign a constant and the name they want is applePie. The .value that you are using is not correct, so that can be safely removed.

Also, you've managed to misspell the name of the dictionary. In the line where you're trying to retrieve the value at "AP", you've spelled it icecream instead of iceCream. This will result in an "unresolved identifier" compiler error if not corrected. Remember, capitalization matters here.

I hope this helps, but please let me know if you're still stuck! :sparkles: