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

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,861 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,861 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!