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 trialMichael Bau
3,394 Points3rd code challenge: What is meant by 'Retreive'?
Hi,
In the 3rd code challenge, you are asked to 'Retrieve the value for apple pie...'.
I have tried a number of things, among others:
iceCream["AP"] followed by let applePie = ["Apple Pie"] as 'Apple Pie is the value shown when reading from the dictionary.
However, I get the error message: 'Make sure you are retrieving a value from the dictionary rather than assigning a string directly".
I donΒ΄t know how to proceed, I have tried quite a number of combinations, so I would appreciate som assistance on this.
Thanks in advance and best regards, Michael
// 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 = ["Apple Pie"]
6 Answers
Steve Hunter
57,712 PointsHi Michael,
The reason for the error is that you have a line of code that receives the retrieved value but that value isn't picked up by anything. Having iceCream["AP"]
alone like that in your code means that the value "Apple Pie" is retrieved but never assigned to anything. The challenge compiler doesn't like that.
I added a comment in your code. If you delete that line, this should now pass the challenge.
Steve.
Steve Hunter
57,712 PointsHi Michael,
You've pretty much got that in your code already.
You access the iceCream
dictionary by passing in the key to retrieve its associated value. Use square brackets and assign the result into the constant called applePie
. Like this:
let applePie = iceCream["AP"]
Steve.
Michael Bau
3,394 PointsHi Steve,
Thanks a lot for your quick reply!
To be honest, I have yet to figure out how to add screen shots to the comments, but here is what I wrote in the challenges (1-3):
var iceCream = ["CC": "Chocolate Chip", "AP": "Apple Pie", "PB": "Peanut Butter"]
iceCream.updateValue("Rocky Road", forKey: "RR")
iceCream["AP"] // <- this returns the value "Apple Pie" but it isn't used
let applePie = iceCream["AP"]
The complete error message reads: swift_lint.swift:24:9: error: expression resolves to an unused l-value iceCream["AP"]
Best regards, Michael
Michael Bau
3,394 PointsHi Steve,
Thanks a lot, that did the trick!
Best regards, Michael
Steve Hunter
57,712 PointsNo problem! Happy to help.
Michael Bau
3,394 PointsHi again,
Thanks to the answer from Steve above, I managed to complete the 3rd code challenge, but unfortunately had to leave right after, before completing task 4.
That meant that I had to go through the first 3 challenges again, today. Now, despite doing exactly as shown yesterday (where it worked like a charm!), I get a new error message = 'expression resolves to an unused l-value'.
When I replicate the code in Xcode it works without problems, so I can't see what the issue could be here!
Best regards, Michael
Steve Hunter
57,712 PointsHi Michael,
If you could copy your code and maybe screen shot the error, that would help.
I'm sure we can fix the issue.
Steve.
Michael Bau
3,394 PointsHi Steve,
Once again, thank you very much - you are a true life-saver :o) It was really getting on my nerves!
Once I deleted the stand-alone 'iceCream["AP"]', I was able to proceed and complete the challenge.
Best regards, Michael
Steve Hunter
57,712 PointsNo problem - glad you got it fixed.