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 Introduction to Dictionaries

Matthew Daugherty
Matthew Daugherty
1,017 Points

Trouble with Dictionaries

Hello,

I am trying to insert the String to String tag on my dictionary, but I am getting an error message.

This is the code I have:

let airportCodes: [String: String] = [ "LGA: La Guardia", "LHR: Heathrow", "CDG: Charles de Gualle", "HKG: Hong Kong International", "DXB: Dubai Internation"]

There are no errors until I put in "[String: String]" The error message reads: "Contextual type '[String: String]' cannot be used with array literal."

I'm trying to follow the on screen instructions as closely as possible, so any help is appreciated. Thanks!

1 Answer

Sathya vegunta
Sathya vegunta
4,061 Points

Hi,

As Strings will be in double quotes, we need to have the key string and value string in double quotes individually, instead of clubbing them. Below is the syntax: let airportCodes: [String: String] = [ "LGA": "La Guardia", "LHR": "Heathrow", "CDG": "Charles de Gualle", "HKG": "Hong Kong International", "DXB": "Dubai Internation"]

Matthew Daugherty
Matthew Daugherty
1,017 Points

That was precisely my problem. Thank you so much!