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 Basics (retired) Collections What is a Dictionary?

David Liu
David Liu
2,255 Points

I think you guys forgot to add the code here for your Playground file! :p

As stated.

2 Answers

Hi David

What's missing, exactly? I thought this course started with a fresh playground.

Steve.

David Liu
David Liu
2,255 Points

Hey,

Usually the source code for the code written in the tutorial is completed and posted up as a downloadable .zip file. Unless my eyes are being funny, I think this particular lecture was missing one.

It's not a huge issue but I thought I'd just alert you guys to it.

Loving the TreeHouse courses by the way, they're brilliant - simple, well-articulated, and builds a solid conceptual framework so I actually understand why I would or wouldn't do things in coding.

David

Ah - right. I'm not sure that TH put up the Playgrounds but I will ask - thanks for pointing that out.

Glad you're enjoying the courses. I'm just like you - I'm a student on here and have found the courses really useful. The Mod thing is just from being in the forums helping other students and completing a range of topics. That's open to anyone.

Keep coding and enjoying! If I can help at all, just shout on here or on Twitter; I'm @OnlySteveH.

Steve.

Hi. I didn't see any zip to download, as mentioned above, so I'll share my code. I'm a student so user beware ...

// Dictionary

import UIKit


// Code     Country Name
// or 
// Key  Value
// CA   Canada
// BE   Belgium
// FR   France
// DE   Germany
// UK   United Kingdom
// US   United States


var countries = [ "CA": "Canada", 
"BE":   "Belgium",
"FR":   "France",
"DE":   "Germany",
"UK":   "United Kingdom",
"US":   "United States"
]

// so we just provide key value rather than an index

countries["CA"] // his example shows "{Some "Canada"}" returned whereas my xcode shows just "Canada" returned

countries["dumb country doesn't exist"] // so get nil value

countries["CL"] = "Chile" // add Chile to the Dictionary, no particular order, just indexed

countries

countries["US"] = "United States of America" // US Dictionary value is updated with new string
countries



let item = countries.removeValueForKey("CA")
item

// an array holds an ordered list of values
// a dictionary holds an UN-ordered list of key-value pairs