Fatal error unwrapping when trying to save a segued text photo

I am trying to make a photo app. Depending on the buttons you press it will choose your photo frame. The app includes the ability for the user to enter a custom message to be included in the picture frame. This works perfectly with one of the possible frame options but with the other 3 it gives the fatal error unwrapping message

This is the code for the user to choose the frame they want for there photo.

import UIKit

class ltwoViewController: UIViewController {


@IBOutlet var textFIELD: UITextField!
@IBOutlet var redBUTTON: UIButton!
@IBOutlet var brownBUTTON: UIButton!
@IBOutlet var blueBUTTON: UIButton!
@IBOutlet var greenBUTTON: UIButton!
@IBOutlet var newbutton: UIButton!
@IBOutlet var timerLABEL: UILabel!
@IBOutlet var score1level: UILabel!

@IBOutlet var soccerBall: UIButton!

var level = 0
var timer: Timer?
var isRunning: Bool {
    get {
        return timer != nil
    }}
var counter = 0.0




override func viewDidLoad() {
    super.viewDidLoad()

          if isRunning {
        return
    }
    refreshTimer()
    

        }


func refreshTimer() {
    
    if let timer: Timer = timer {
        timer.invalidate()
    }
    timer = Timer.scheduledTimer(timeInterval: 0.1 ,target: self,selector: #selector(updateTimer),userInfo: nil, repeats: true)
    
}



@IBAction func gBUTTON(_ sender: Any) {
    level += 1
    blueBUTTON.isHidden = true
    
}
@IBAction func bBUTTON(_ sender: Any) {
    level += 11
    greenBUTTON.isHidden = true
}
@IBAction func brownBUTTON(_ sender: Any) {
    level += 2
}
@IBAction func redBUTTON(_ sender: Any) {
    level += 3
}


func updateTimer() {
    
    if counter < 14.9 && level == 3 {
        if let nextc = self.storyboard?.instantiateViewController(withIdentifier: "greenViewController") as? greenViewController {
            
            nextc.labelText = textFIELD.text!
            
            
            self.present(nextc, animated: true, completion: nil)
            timer?.invalidate()
            
            
        }}
    counter += 0.1
            if counter < 14.9 && level == 4 {
        
            if let nextc = self.storyboard?.instantiateViewController(withIdentifier: "blueViewController") as? blueViewController {
                nextc.labelText = textFIELD.text!
                self.present(nextc, animated: true, completion: nil)
            
                       
 
        }}
        

    if counter < 14.9 && level == 13 {
        if let nextc6 = self.storyboard?.instantiateViewController(withIdentifier: "silverViewController") as? silverViewController {
            
            nextc6.labelText2 = textFIELD.text!

            
            self.present(nextc6, animated: true, completion: nil)
            
            timer?.invalidate()
        }}
    if counter < 14.9 && level == 14 {
        if let nextc4 = self.storyboard?.instantiateViewController(withIdentifier: "lightBlueViewController") as? lightBlueViewController {
            
               nextc4.labelText = textFIELD.text!
            
            self.present(nextc4, animated: true, completion: nil)
            
            timer?.invalidate()
        }}
        
    else if  counter >= 15{
        let next = self.storyboard?.instantiateViewController(withIdentifier: "loseViewController") as? loseViewController
        self.present(next!, animated: true, completion: nil)
        timer?.invalidate()
    }}}

This is the code for the view controller that works.

    extension CALayer {
func addBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat) {
    
    let border = CALayer();
    
    switch edge {
    case UIRectEdge.top:
        border.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: 10)
        break
    case UIRectEdge.bottom:
        border.frame = CGRect(x:0, y:self.frame.height - thickness, width:self.frame.width, height:thickness)
        break
    case UIRectEdge.left:
        border.frame = CGRect(x:0, y:0, width: thickness, height: self.frame.height)
        break
    case UIRectEdge.right:
        border.frame = CGRect(x:self.frame.width - thickness, y: 0, width: thickness, height:self.frame.height)
        break
    default:
        break
    }
    
    border.backgroundColor = color.cgColor;
    
    self.addSublayer(border)
}}


import UIKit

class blueViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
@IBOutlet var imageDISPLAY: UIImageView!
 var screenView: UIImageView!

@IBOutlet var zext: UILabel!
 var labelText = String()


override func viewDidLoad() {
    super.viewDidLoad()

    zext.text = labelText
}


@IBAction func saveThePhoto(_ sender: Any) {
    
    let alert = UIAlertController(title: "Image Saved", message: "Image is in photo gallery", preferredStyle: .alert)
    let okay = UIAlertAction(title: "OK", style: .default, handler: nil)
    alert.addAction(okay)
    present(alert, animated: true, completion: nil)
    
    let photo = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(photo!, nil, nil, nil)

    
}
@IBAction func takeTHePhoto(_ sender: Any) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        
        
        
        imageDISPLAY.layer.addBorder(edge: [.top], color: UIColor.red, thickness: 12.0)
        imageDISPLAY.layer.addBorder(edge: [.bottom], color: UIColor.red, thickness: 180.0)
        imageDISPLAY.layer.addBorder(edge: [.left], color: UIColor.red, thickness: 50.0)
        imageDISPLAY.layer.addBorder(edge: [.right], color: UIColor.red, thickness: 50.0)
        
        
        
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)}}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject: AnyObject]!){
    imageDISPLAY.image = image
    self.dismiss(animated: true, completion: nil);
    screenView = UIImageView()
    
    screenView.frame = CGRect(x:0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
    
    
    
    let label = zext
    label?.font = UIFont(name: (label?.font.fontName)!, size: 122)
    label?.frame = (frame: CGRect(x: 125, y: 700, width: self.view.frame.width, height: 300))
    
    
    label?.textColor = UIColor.green
    label?.alpha = 1.0
    
    self.view.addSubview(screenView)
    self.view.addSubview(label!)
    
    
    
    UIGraphicsBeginImageContext(self.imageDISPLAY.frame.size)
    self.view.drawHierarchy(in: self.view.frame, afterScreenUpdates: true)

}}

This is the code for the other view controller that does not work. The message will be transferred however when it comes to saving the photo in the image view. That is when the error message occurs.

  import UIKit

class silverViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {

@IBOutlet var zext2: UILabel!
var labelText2 = String()

@IBOutlet var IMAGEDISPLAY: UIImageView!
var screenView2: UIImageView!



override func viewDidLoad() {
    super.viewDidLoad()
       zext2.text = labelText2

        }
@IBAction func takePHOTO(_ sender: Any) {
    
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        
        
        
        IMAGEDISPLAY.layer.addBorder(edge: [.top], color: UIColor.red, thickness: 12.0)
        IMAGEDISPLAY.layer.addBorder(edge: [.bottom], color: UIColor.red, thickness: 180.0)
        IMAGEDISPLAY.layer.addBorder(edge: [.left], color: UIColor.red, thickness: 50.0)
        IMAGEDISPLAY.layer.addBorder(edge: [.right], color: UIColor.red, thickness: 50.0)
        
        
        
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)}}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject: AnyObject]!){
    IMAGEDISPLAY.image = image
    self.dismiss(animated: true, completion: nil);
    IMAGEDISPLAY = UIImageView()
    
    IMAGEDISPLAY.frame = CGRect(x:0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
    
    
    
    let label2 = zext2
    label2?.font = UIFont(name: (label2?.font.fontName)!, size: 122)
    label2?.frame = (frame: CGRect(x: 125, y: 700, width: self.view.frame.width, height: 300))
    
    
    label2?.textColor = UIColor.blue
    label2?.alpha = 1.0
    
    self.view.addSubview(screenView2)
    self.view.addSubview(label2!)
    
    
    
    UIGraphicsBeginImageContext(self.IMAGEDISPLAY.frame.size)
    self.view.drawHierarchy(in: self.view.frame, afterScreenUpdates: true)

}
@IBAction func savePHOTO(_ sender: Any) {
    let alert = UIAlertController(title: "Image Saved", message: "Image is in photo gallery", preferredStyle: .alert)
    let okay = UIAlertAction(title: "OK", style: .default, handler: nil)
    alert.addAction(okay)
    present(alert, animated: true, completion: nil)
    
    let photo = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(photo!, nil, nil, nil)

}}

Hello @zalubski

Hope you have found solution. If not then here you can try.

This error you got because of some nil value. In your piece of code somewhere you got nil value and you are doing some operation on that, so it will rise error. So first check condition of nil like :

if someObject != nil {
    // your code
} else {
    // return or show alert or do nothing
}

If you want to catch where error rise, then refers below screenshot

you will surely got idea where something was wrong.