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

Osama Rehman
Osama Rehman
1,098 Points

Assign value to a constant

So I'm on task 3 out of 4 and it tells me to assign a value from an array to a constant. For some reason it works in Xcode, but not in the treehouse compiler.

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

iceCream["AP"]

let applePie = iceCream["AP"]

2 Answers

Lana Wong
Lana Wong
3,968 Points

Hi Osama,

Try it without the:

iceCream["AP"]

I think it does not work with the treehouse complier because it is programmed to only recognize the correct way to specifically solve these challenges. You can add something totally random, like identify a variable in Xcode, and it would work. But if you do it in the treehouse complier, it would not work because it is set to recognize if you did what the instructions asked you to do.

Lana

Jonathan Hector
Jonathan Hector
5,225 Points
var iceCream = ["CC": "Chocolate Chip", "AP": "Apple Pie", "PB": "Peanut Butter"]
//iceCream["RR"] = "Rocky Road"
iceCream.updateValue("Rocky Road", forKey: "RR")
iceCream.removeValue(forKey: "AP")
iceCream["AP"] = "Apple Pie"
let applePie = iceCream["AP"]

//Hope that helps