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 Using a Navigation Controller With Segues Modifying the UI

Want to pass a image to destination view controller in the prepareForSegue

I am trying out a few things here. I want to pass a image to destination view controller in the prepareForSegue. In the destinationVC, image view is a iboutlet. This throws an error detailVC.detailImage.image = UIImage(named: "helmet")! as fatal error: unexpectedly found nil while unwrapping an Optional value

However in the source view controller I have a image and I am able to initialize it in view did load with imageView.image = UIImage(named: "helmet")!

How does this work!!!!

Hello Soumin can you share the code with us?

Here is the code

class ViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
    super.viewDidLoad()
    imageView.image = UIImage(named: "helmet")!
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func launchDetail(sender: AnyObject) {
    self.performSegueWithIdentifier("showDetailSegue", sender: nil)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetailSegue" {
       var detailVC = segue.destinationViewController as DetailViewController
       var image = UIImage(named: "helmet")!
        detailVC.detailImage.image = UIImage(named: "helmet")!
    }
}

}