I just wanted to click a picture and display it on UIImageView.
I had defined all needed outlets and actions and here is the code.
But it shows the error.
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var camera: UIButton!
@IBOutlet weak var gallery: UIButton!
@IBOutlet weak var viewImage: UIImageView!
@IBAction func PhotoGalleryAction(sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .PhotoLibrary
presentViewController(picker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
viewImage.image = info[UIImagePickerControllerOriginalImage] as? UIImage
dismissViewControllerAnimated(true, completion: nil)
}
}
Here is the error:
fatal error: unexpectedly found nil while unwrapping an Optional value