Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) in required init?(coder aDecoder: NSCoder)

I've received an error runtime Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) at line 10


import UIKit
class FourthViewController: UIViewController {
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        tabBarItem.title = "Settings"
        tabBarItem.image = UIImage(named: "settings")
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        //fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        /
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
}


My implemenation at AppDelegate


import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        /
        if
            let tabBarController = window?.rootViewController as? UITabBarController,
            let viewControllers = tabBarController.viewControllers {
            let fourthViewController: FourthViewController = FourthViewController(nibName: "FourthViewController", bundle: nil)
            tabBarController.viewControllers = viewControllers + [fourthViewController]
        }
        return true
    }
    func applicationWillResignActive(_ application: UIApplication) {
        /
        /
    }
    func applicationDidEnterBackground(_ application: UIApplication) {
        /
        /
    }
    func applicationWillEnterForeground(_ application: UIApplication) {
        /
    }
    func applicationDidBecomeActive(_ application: UIApplication) {
        /
    }
    func applicationWillTerminate(_ application: UIApplication) {
        /
    }
}

Error log as below

2017-10-13 12:53:21.228604 TabSample[5492:205002] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-10-13 12:53:21.325 TabSample[5492:205002] *** Assertion failure in -[UIView _addConstraint:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3599.6/NSLayoutConstraint_UIKitAdditions.m:740
2017-10-13 12:53:21.340 TabSample[5492:205002] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [constraint isKindOfClass:[NSLayoutConstraint class]]'
*** First throw call stack:
(
     0   CoreFoundation                      0x0000000109abc34b __exceptionPreprocess + 171
     1   libobjc.A.dylib                     0x0000000106bec21e objc_exception_throw + 48
     2   CoreFoundation                      0x0000000109ac0442 +[NSException raise:format:arguments:] + 98
     3   Foundation                          0x0000000106782edd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
     4   UIKit                               0x0000000107a84bb6 -[UIView(UIConstraintBasedLayout) _addConstraint:] + 181
     5   UIKit                               0x0000000107a84de2 __50-[UIView(UIConstraintBasedLayout) addConstraints:]_block_invoke + 208
     6   UIKit                               0x0000000107a84d03 -[UIView(UIConstraintBasedLayout) addConstraints:] + 277
     7   UIKit                               0x000000010714ffcf -[UIView initWithCoder:] + 2292
     8   UIKit                               0x00000001076c4dbd UINibDecoderDecodeObjectForValue + 684
     9   UIKit                               0x00000001076c4b0a -[UINibDecoder decodeObjectForKey:] + 98
     10  UIKit                               0x00000001074c915c -[UIRuntimeConnection initWithCoder:] + 178
     11  UIKit                               0x00000001076c4dbd UINibDecoderDecodeObjectForValue + 684
     12  UIKit                               0x00000001076c4f73 UINibDecoderDecodeObjectForValue + 1122
     13  UIKit                               0x00000001076c4b0a -[UINibDecoder decodeObjectForKey:] + 98
     14  UIKit                               0x00000001074c8300 -[UINib instantiateWithOwner:options:] + 1249
     15  UIKit                               0x000000010725bff5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
     16  UIKit                               0x000000010725c917 -[UIViewController loadView] + 177
     17  UIKit                               0x000000010725cc4c -[UIViewController loadViewIfRequired] + 201
     18  UIKit                               0x000000010725d4a0 -[UIViewController view] + 27
     19  UIKit                               0x00000001072bb6b3 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 483
     20  UIKit                               0x00000001072baaf5 -[UITabBarController transitionFromViewController:toViewController:] + 59
     21  UIKit                               0x00000001072b69b6 -[UITabBarController _setSelectedViewController:] + 365
     22  UIKit                               0x00000001072b6838 -[UITabBarController setSelectedViewController:] + 234
     23  UIKit                               0x00000001072ba9a2 -[UITabBarController _tabBarItemClicked:] + 369
     24  UIKit                               0x00000001070bdb88 -[UIApplication sendAction:to:from:forEvent:] + 83
     25  UIKit                               0x00000001074d60ba -[UITabBar _sendAction:withEvent:] + 579
     26  UIKit                               0x00000001070bdb88 -[UIApplication sendAction:to:from:forEvent:] + 83
     27  UIKit                               0x00000001072432b2 -[UIControl sendAction:to:forEvent:] + 67
     28  UIKit                               0x00000001072435cb -[UIControl _sendActionsForEvents:withEvent:] + 444
     29  UIKit                               0x00000001074d8842 -[UITabBar _buttonUp:] + 113
     30  UIKit                               0x00000001070bdb88 -[UIApplication sendAction:to:from:forEvent:] + 83
     31  UIKit                               0x00000001072432b2 -[UIControl sendAction:to:forEvent:] + 67
     32  UIKit                               0x00000001072435cb -[UIControl _sendActionsForEvents:withEvent:] + 444
     33  UIKit                               0x00000001072424c7 -[UIControl touchesEnded:withEvent:] + 668
     34  UIKit                               0x000000010712b0d5 -[UIWindow _sendTouchesForEvent:] + 2747
     35  UIKit                               0x000000010712c7c3 -[UIWindow sendEvent:] + 4011
     36  UIKit                               0x00000001070d9a33 -[UIApplication sendEvent:] + 371
     37  UIKit                               0x00000001078cbb6d __dispatchPreprocessedEventFromEventQueue + 3248
     38  UIKit                               0x00000001078c4817 __handleEventQueue + 4879
     39  CoreFoundation                      0x0000000109a61311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
     40  CoreFoundation                      0x0000000109a4659c __CFRunLoopDoSources0 + 556
     41  CoreFoundation                      0x0000000109a45a86 __CFRunLoopRun + 918
     42  CoreFoundation                      0x0000000109a45494 CFRunLoopRunSpecific + 420
     43  GraphicsServices                    0x000000010b96ba6f GSEventRunModal + 161
     44  UIKit                               0x00000001070bbf34 UIApplicationMain + 159
     45  TabSample                           0x0000000106609927 main + 55
     46  libdyld.dylib                       0x000000010a9e668d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException


I only use one FourthViewController View Controller to manage FourthViewController.xib view. Everything is ok when build and load other views but can not load its view. What's happen in environment Xcode 9.0 and Swift 3.2 or Swift 4.0 (aslo error)?

Accepted Reply

I've resolved this issue that crashes app. You can contact me via email norman@enclave.vn to fix that bug

Replies

I've resolved this issue that crashes app. You can contact me via email norman@enclave.vn to fix that bug