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 trialNissan Levy
408 PointsupdateValue
how to use updateValue on a dictionary
// Enter your code below
var iceCream = [
"CC": "Chocolate Chip",
"AP": "Apple Pie",
"PB": "Peanut Butter"
]
iceCream.updateValue("Rockey Road", forKey: "RR")
2 Answers
guipriaulx
551 PointsYour 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
2,032 PointsI 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
2,032 PointsYour 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!
Candace Sommer-Van Auken
2,032 PointsCandace Sommer-Van Auken
2,032 PointsYour 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!