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

Lauri For Apss
Lauri For Apss
1,810 Points

I am having a hard time understanding the given task to do. Could someone elaborate it a bit more. Thank YOU!

How do I have the wrong key word? If I am assigning it as it is in the friends struct.

ImageViews.swift
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

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


    }

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

1 Answer

Jason Safdie
Jason Safdie
3,461 Points

With these challenges and coding in general, it's really easy to fall into a trap of thinking you need to write more code than you have to. I fall into that trap sometimes too! Look at my code below and how it only required two relatively straightforward lines of code, then reread the challenge. You'll see the successful code fulfills the exercise without wasting a single dot or bracket! ;-) Hope this helps clear things up!

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let friends = Treehouse().friends

        //Add your code below

        let profileImageName = friends["profilePicture"]!
        let profilePicture = UIIMage().profileImageName


    }

}