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

Need help creating a dictionary

Im not sure what Im doing wrong here. Any ideas?

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

4 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Luke,

Your dictionary definition is spot on (but bear in mind that you don't need to explicitly specify the type when the compiler can infer the type).

Your error is that you've copied the key value pairs into the lines above your dictionary definition where they are invalid syntax (and redundant since you specify those key value pairs again in your dictionary definition itself).

Hope that helps

Cheers

Alex

Still not sure how that would look.

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Luke,

What I mean is that your last line is correct and is the whole solution to the challenge. Your other lines are invalid syntax and should just be deleted.

Cheers

Alex

Ok I see. Thanks!