Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problems with unwinding a segue

Having a real issue with this.

I have now managed to transfer my label data across a segue and display it on a new view controller. Thank you to all of those who helped with this. For this I used the following code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let BMI_Result = segue.destination as! BMI_Result
    
    if let text = result3Label.text {
        BMI_Result.text = text
    }

The problem I am having now is that when I try to unwind segue using a back button from this view, the app crashes and I get the following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • Thread 1: signal SIGABRT

The as! command in the code has a red underline.

I have read up on the signal SIGABRT error and from what I can see, it’s a generic error for that line of code. I presume it is because this code is linked to another segue but I don’t know how to correct it.

Anyone got any ideas?

I have attempted to redo the back segue and link the button to the contents page. None of this has worked.

>Solution :

The issue here is the force cast as!. As you go back your destination has changed.

Change this to an optional cast and guard against it.

guard let BMI_Result = segue.destination as? BMI_Result else{
    return
}

if let text = result3Label.text {
    BMI_Result.text = text
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading