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 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

    }