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!

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 Playlist Browser with Swift Building the Music Library and Playlist Models Creating UIImageView instances

Jon Schenck
Jon Schenck
2,028 Points

trying to acquire a dictionary value

Need help solving this

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {

        let friends = Treehouse().friends

        let profileImageName = ViewController(index: profilePicture)
        let profilePicture = profilePicture.icon


struct Treehouse {
    let friends = [
        "firstName": "Susan",
        "lastName": "Olson",
        "profilePicture": "susan_profile.png"

1 Answer

Christopher Augg
Christopher Augg
21,223 Points

Heya Jon,

You need to access the friends dictionary by using the key "profilePicture" and assign it to a constant named profileImageName and unwrapping String optional. Once you have the name, you instantiate the UIImage with it and assign that to a constant named profilePicture.

 //Add your code below
 let profileImageName = friends["profilePicture"] as String!        
 let profilePicture : UIImage =  UIImage(named: profileImageName) 

Hope this helps.