Search code examples
iosswiftsegueibaction

libc++abi.dylib segue error with uncaught exception of type NSException


I have three view controllers in total. I pressed Cntrl on the first view controller and created a segue to the second one on the bottom right (haven't tested the top right one yet). Storyboard is below:

enter image description here

The description of the second segue from the bottom is:

enter image description here

I have placed the segues inside an the IBAction for the button at the bottom of the first view controller. The code is as below:

class ViewController: UIViewController {
    
    private lazy var app = ProjectApp()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    @IBAction func start_test(_ sender: Any) {
        if app.is_facial_analysis_completed() {
            DispatchQueue.main.async() {
                self.performSegue(withIdentifier: "home_to_quiz", sender: self)
            }
        } else {
            DispatchQueue.main.async() {
                self.performSegue(withIdentifier: "home_to_vision", sender: self)
            }
        }
    }

}

Not really sure as to why I am getting this error:

libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Here is the code for the quiz view class:

import UIKit

class QuizViewController: UIViewController {
    
    @IBOutlet var QuizView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

Here is a screenshot of the view controller of the quizViewController:

enter image description here

The Full ERROR

2019-11-20 02:02:34.141705+0400 XXX[47921:9768662] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fd98a7088b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key QuizView.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23baa1ee __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50864b20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23ba9db9 -[NSException raise] + 9
    3   Foundation                          0x00007fff2563e130 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 325
    4   UIKitCore                           0x00007fff46f008e9 -[UIViewController setValue:forKey:] + 87
    5   UIKitCore                           0x00007fff471ec3fa -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x00007fff23b96212 -[NSArray makeObjectsPerformSelector:] + 242
    7   UIKitCore                           0x00007fff471e95a2 -[UINib instantiateWithOwner:options:] + 2190
    8   UIKitCore                           0x00007fff46f07b3b -[UIViewController _loadViewFromNibNamed:bundle:] + 395
    9   UIKitCore                           0x00007fff46f08660 -[UIViewController loadView] + 177
    10  UIKitCore                           0x00007fff46f0895f -[UIViewController loadViewIfRequired] + 172
    11  UIKitCore                           0x00007fff46f0910c -[UIViewController view] + 27
    12  UIKitCore                           0x00007fff46f2038e -[UIViewController _setPresentationController:] + 100
    13  UIKitCore                           0x00007fff46f18b9a -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1256
    14  UIKitCore                           0x00007fff46f1a602 -[UIViewController _presentViewController:withAnimationController:completion:] + 4325
    15  UIKitCore                           0x00007fff46f1ce7b __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
    16  UIKitCore                           0x00007fff46f1d393 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
    17  UIKitCore                           0x00007fff46f1cdd9 -[UIViewController _presentViewController:animated:completion:] + 187
    18  UIKitCore                           0x00007fff46f1d040 -[UIViewController presentViewController:animated:completion:] + 150
    19  UIKitCore                           0x00007fff46f2131f -[UIViewController _showViewController:withAction:sender:] + 272
    20  UIKitCore                           0x00007fff476d69b7 __66-[UIStoryboardShowSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 134
    21  UIKitCore                           0x00007fff476dc410 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 276
    22  UIKitCore                           0x00007fff476dc2ce -[UIStoryboardSegueTemplate _perform:] + 82
    23  UIKitCore                           0x00007fff46f0be3b -[UIViewController performSegueWithIdentifier:sender:] + 99
    24  XXX                                 0x000000010d49b896 $s3XXX14ViewControllerC19pulse_permute_segueyyFyycfU_ + 118
    25  XXX                                 0x000000010d494c7d $sIeg_IeyB_TR + 45
    26  libdispatch.dylib                   0x000000010d954df8 _dispatch_call_block_and_release + 12
    27  libdispatch.dylib                   0x000000010d955d6c _dispatch_client_callout + 8
    28  libdispatch.dylib                   0x000000010d963e24 _dispatch_main_queue_callback_4CF + 1500
    29  CoreFoundation                      0x00007fff23b0ce49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    30  CoreFoundation                      0x00007fff23b07aa9 __CFRunLoopRun + 2329
    31  CoreFoundation                      0x00007fff23b06e66 CFRunLoopRunSpecific + 438
    32  GraphicsServices                    0x00007fff38346bb0 GSEventRunModal + 65
    33  UIKitCore                           0x00007fff47578dd0 UIApplicationMain + 1621
    34  XXX                                 0x000000010d4a724b main + 75
    35  libdyld.dylib                       0x00007fff516ecd29 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Solution

    1. Maybe you need to add UINavigationViewController like Initial View Controller?

    enter image description here

    Or you need override this method and setup some required data on second controller?

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            if (segue.identifier == "home_to_quiz") {
               let dectinationView = segue.destination as! YourCustomViewController
               dectinationView.dataContainer = self.dataContainer
            }
        }
    

    Addition

    1. Here are a few moments where something could go wrong:

      • Class of your UIViewController must be Inherit From Target

    enter image description here

    • Try to delete your Selector (home_to_quiz:) in Storyboard. Do you implement a selector method inside a controller?