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
victorsanchez2
6,577 PointsMy playlistImageView0.image = playlist.icon is throwing an optional is nil fatal error
My build is successful but when my simulator loads the app it fails. I get a "fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)" in my command line and I can't seem to find out what the problem is.
I have all the images in place and the dictionary is all good.
It worked three times before then suddenly it broke
error happens on this line: playlistImageView0.image = playlist.icon
I also see this in my debugger: playlistImageView0=(UIImageView!) nil None
My PlaylistMasterView:
import UIKit
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 // The Error happens here
playlistImageView0.backgroundColor = playlist.backGroundColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showPlaylistDetail" {
let playlistDetailController = segue.destinationViewController as! PlayListDetailViewControllwerViewController
playlistDetailController.playlist = Playlist(index: 0)
}
}
}
My List Detail:
class PlayListDetailViewControllwerViewController: UIViewController {
@IBOutlet weak var pressedButtonLabel: UILabel!
var playlist: Playlist?
override func viewDidLoad() {
super.viewDidLoad()
if playlist != nil {
pressedButtonLabel.text = playlist!.title
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}