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

Swift 2.0

Challenge Task 2 of 4

An ice cream shop with only three flavors would be somewhat limited. Let's add another flavor to the list!

Add the value, "Rocky Road", for the key "RR" to the iceCream dictionary.

You can either add it using subscript syntax or the method updateValue(value: Value, forKey key: Key). The method takes a value and a key. Example: updateValue("Pistachio", forKey: "PI")

I am Stak ....

dictionary.swift
// Enter your code below

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

               updateValue (value: Value, forKey key: Key)
               updateValue ("Pistachio", forKey: "PI")

4 Answers

Ian Rushton
Ian Rushton
15,789 Points

I did this a different way.

First make sure that your dictionary looks like this:

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

Then, using the subscript syntax I added the value for Rocky Road as follows:

iceCream["RR"] = "Rocky Road"

The other way to do this is:

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

Does this help? I notice that your code looks like you may be on a different stage, if this is the case let me know and I'll give it another try!

An ice cream shop with only three flavors would be somewhat limited. Let's add another flavor to the list!

you good thank you

iceCream["RR"] = "Rocky Road"