Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Playlist Browser with Swift Building the Music Library and Playlist Models Using a Playlist Instance

Aaron Anderson
Aaron Anderson
2,541 Points

Image won't load

I copied the exact code but when i run the app.... the image wont load. Just the background color of the UIView shows. Help?

class PlaylistMasterViewController: UIViewController {

@IBOutlet weak var aButton: UIButton!
@IBOutlet weak var playlistView1: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()

    aButton.setTitle("Press This Button!", forState: .Normal)
    let playlist = Playlist(index: 0)
    playlistView1.image = playlist.icon
}

Have made sure that you copied the images to the image assets?

Aaron Anderson
Aaron Anderson
2,541 Points

yes i used drag and drop to place the images inside the image asset as well as changed it to a vetor

2 Answers

Had the same problem and found my solution when I rechecked my code. Go to your Playlist file and check for unnecessary quotation marks given to iconName.

let iconName = playlistDictionary["icon"] as! String!
        icon = UIImage(named: iconName)
Jack Hawley
Jack Hawley
10,665 Points

It looks like a simple typo. You set the outlet variable as "playlistView1" and it should be "playlistView0" because you are referencing index 0

Try this:

class PlaylistMasterViewController: UIViewController {

    @IBOutlet weak var aButton: UIButton!
    @IBOutlet weak var playlistImageView0: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        aButton.setTitle("Press me!", forState: .Normal)

        let playlist = Playlist(index: 0)
        playlistImageView0.image = playlist.icon

    }