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 2.0 Collections and Control Flow Dictionaries Working with Dictionaries

not sure how to get this done,

I'm confused about the question and what is asked by the task 3

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Cyrille Najjar,

Task 3 asks:

Let's pretend a customer has ordered an ice cream. Retrieve the value for apple pie using the correct key and assign it to a constant named applePie.

You can retrieve the value for for apple pie by using its key. In the dictionary you created in the first task, you created a key value pair of "AP": "Apple Pie". Therefore, to access the value of apple pie, you need to use its key "AP".

You can do this by writing the dictionary name followed by the correct key in brackets. dictionaryName["key"]

The question also asks you to assign the value retrieved to a constant named applePie. Remember, this value will be returned as an optional value, since it is possible for you to pass in an invalid key.

let applePie = iceCream["AP"]

applePie is now of type String? with a value of "Apple Pie"

Hope this helps!