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 trialKelvin Brooks
1,488 PointsHow 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")
iceCream["AP"]
let applePie = iceCream ["AP"]
1 Answer
Alexander Davison
65,469 PointsIt seems that Swift doesn't like this line:
iceCream["AP"]
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!)
Kelvin Brooks
1,488 PointsKelvin Brooks
1,488 PointsWell 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.
Kelvin Brooks
1,488 PointsKelvin Brooks
1,488 PointsSo 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!