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

Nissan Levy
Nissan Levy
408 Points

updateValue

how to use updateValue on a dictionary

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

iceCream.updateValue("Rockey Road", forKey: "RR")
Candace Sommer-Van Auken
Candace Sommer-Van Auken
2,032 Points

Your problem is in your first line. To declare a dictionary, you need to have a first line like this: var iceCream: [String: String] = [ Without the "[String: String]" you aren't declaring a dictionary, just a messed up array! Hope this helps!

2 Answers

Your implementation is correct. Contrary to Candace's answer, type inference is used to determine what to make, and it certainly won't assume it is an array. If this is for a code challenge and things aren't working, you may have missed something else that is a requirement of the challenge. I have found a few problems with the way code challenges work here, and what they accept. If all else fails, try it in a playground in xcode, make sure you are happy with your learning outcome, and move on; it's not worth getting hung up on a TreeHouse bug :).

Candace Sommer-Van Auken
Candace Sommer-Van Auken
2,032 Points

I tried out his code in a playground, and it didn't run. Changing the first line as I suggested got it to run in a playground.

Candace Sommer-Van Auken
Candace Sommer-Van Auken
2,032 Points

Your problem is in your first line. To declare a dictionary, you need to have a first line like this: var iceCream: [String: String] = [ Without the "[String: String]" you aren't declaring a dictionary, just a messed up array! Hope this helps!