Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Collections and Control Flow Dictionaries in Swift Working With Dictionaries

How am I supposed to retrieve the value of "AP" from iceCream without using iceCream["AP"] in order to reassign it.

The challenge is to take the value and reassign the value "Apple Pie" paired with the key "AP" in the iceCream dictionary to a new constant dictionary named applePie. But it says I must retrieve the value then assign it but so far no luck on using iceCream["AP"] to then reassign the value that is supposed to appear over to = let applePie

// Enter your code below
var iceCream = ["CC" : "Chocolate Chip", "AP" : "Apple Pie", "PB" : "Peanut Butter"]
iceCream.updateValue("Rocky Road", forKey: "RR")
let applePie = iceCream ["AP"]

1 Answer

It seems that Swift doesn't like this line:


Swift probably thought you were trying to reassign "AP", but you didn't, so it responded with an error. Remove the line and it should pass. (Sorry if I'm wrong; I haven't used Swift in a while!)

Well as far as I can figure out, I don't know if I can solve it without using iceCream["AP"] cause in the video on modifying a dictionary that is how you make it display the Value for the Key "AP". They refer to it as Reading or Calling the Value assigned to that Key. It keeps telling me that I can not assign the string directly and I must call the value first. But in challenges the value doesn't call. Even when I click preview.

So I started it over from scratch again. But unlike the previous multiple attempts over the last two days instead of using iceCream.updateValue("Rocky Road", forKey: "RR") I used iceCream["RR"] = "Rocky Road". That for some odd reason seemed to be what let it go through in part 3 when I used let applePie = iceCream["AP"] Which I had used before but it never worked cause it always gave me an error telling me I have to call the String from the dictionary first rather than just assigning the string immediately both with and without using an iceCream["AP"] as a standalone attempt to call the value. Thanks for your help and time. Also I recommend revisiting Swift its such a versatile and fun language!