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 Build a Weather App with Swift (Retired) Data Modeling With Structures Creating and accessing Swift Dictionaries

Retrieve Value in Dictionary in SWIFT

The directions are, "Retrieve the language used for iOS development by using the relevant key and dictionary subscripting notation and store it in a variable named iosLanguage."

I feel I followed the instructions but I constantly get an error when I run it. Help!

dictionaries.swift
let languages: Dictionary = ["iOS": "Swift", "Android":"Java"]


var iosLanguage = for value in languages.values.array {
    println("\(value)")
}

2 Answers

Daniel Sattler
Daniel Sattler
4,867 Points

Try this ;-)

let languages = ["iOS": "Swift","Android": "Java"]

var iosLanguage = languages["iOS"]

Make sure you understand WHY it works this way. This is basic dictionary stuff. i highly recommend that you have a look at the Swift Basic Track... pretty good Videos and easy to understand.

You can of course just copy and paste my solution but you will have problems in the future if you donยดt understand what happened.

You wanted to use an for-in Loop and assign it to a variable ... and thatยดs just not how you do it :-)

I hope i can help. Just ask ;-)

I have a similar question as the OP (and the answer above doesn't answer). Say I have a dictionary like this [PFFIle : PFFile]. This exists for an image and it's thumbnail. I need to get from all the PFObjects the image (key) and the thumb (value). How would I go about doing this? I'm not trying to get the value for a specific key. I'm trying to retrieve all the images (keys) and all the thumbs (values) and use them.