daddyhuzzah
daddyhuzzah

Reputation: 21

App crash on every segue after converting AppDelegate to Swift from Objective-C with [__SwiftValue set]: unrecognized selector sent to instance

I have converted an app from Objective-C to Swift 5.1. The last step was to convert AppDelegate. The app was working perfectly until I converted AppDelegate. After conversion, EVERY segue crashes with:

"[__SwiftValue set]: unrecognized selector sent to instance"

I have seven tabs. Each tab works perfectly until I segue to another view controller OR if I select ... More. I am completely baffled. I have set every breakpoint I can think of setting. For example, when I prepare for segue in one of the controllers, it appears that all of the variables are set properly, but as soon as the function exits, the app crashes before loading the next view controller. The breakpoint is always the class AppDelegate statement in the AppDelegate.

What's happening? When I switch back to using the Objective-C version of the AppDelegate, all is well. I assume, something is being released or dereferenced that I can't detect. Here is code around UITabbarController in AppDelegate:

    let tc: UITabBarController? = window?.rootViewController as? UITabBarController
    var items: [UIViewController]? = tc?.viewControllers
    //set tab titles...
    var i: Int = 0
    for nav in items ?? [] {
        guard let nav = nav as? UINavigationController else {
            continue
        }
        let vc: UIViewController? = nav.viewControllers.first
        i += 1
        switch i {
            case 1:
                vc?.title = NSLocalizedString(Globals.kBD_Everyday, comment: "Title for first tab")
            case 2:
                vc?.title = NSLocalizedString(Globals.kBD_People, comment: "Title for second tab")
            case 3:
                vc?.title = NSLocalizedString(Globals.kBD_Places, comment: "Title for third tab")
            case 4:
                vc?.title = NSLocalizedString(Globals.kBD_Tracks, comment: "Title for fourth tab")
            case 5:
                vc?.title = NSLocalizedString(Globals.kBD_Songs, comment: "Title for fifth tab")
            case 6:
                vc?.title = NSLocalizedString(Globals.kBD_Instruments, comment: "Title for sixth tab")
            case 7:
                vc?.title = NSLocalizedString(Globals.kBD_Sources, comment: "Title for last tab")
            default:
                break
        }
    }
    if Globals.my_IS_TEST != 0 {
        //log application document directory
        print("Version \(appVersionString ?? ""), Build: \(appBuildString ?? "")")
        print("\(AppDelegate.applicationDocumentsDirectory()!)")
        print("plist at \(plist)")
    } else {
        //remove data load
        items?.removeLast()
        tc?.viewControllers = items
    }
    //firstObject is a nav controller
    let tabView = tc?.viewControllers?.first as! UINavigationController
    cvc = tabView.viewControllers.first as? ContainerViewController
    cvc?.isThisDay = true

This is the output of the debugger: 2020-02-04 18:23:22.118721-0500 Fab4Everyday[78607:10435517] -[__SwiftValue set]: unrecognized selector sent to instance 0x604000110c10 2020-02-04 18:23:22.125943-0500 Fab4Everyday[78607:10435517] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__SwiftValue set]: unrecognized selector sent to instance 0x604000110c10' * First throw call stack: (

0   CoreFoundation                      0x000000010680627e __exceptionPreprocess + 350
1   libobjc.A.dylib                     0x0000000106673b20 objc_exception_throw + 48
2   CoreFoundation                      0x0000000106826fd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3   CoreFoundation                      0x000000010680ac4c ___forwarding___ + 1436
4   CoreFoundation                      0x000000010680cf78 _CF_forwarding_prep_0 + 120
5   UIFoundation                        0x000000011b0cdf37 -[NSCoreTypesetter _NSFastDrawString:length:attributes:paragraphStyle:typesetterBehavior:lineBreakMode:rect:padding:graphicsContext:baselineRendering:usesFontLeading:usesScreenFont:scrollable:syncAlignment:mirrored:boundingRectPointer:baselineOffsetPointer:wantsTextLineFragments:drawingContext:] + 2621
6   UIFoundation                        0x000000011b0cf388 -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:graphicsContext:forceClipping:attributes:stringDrawingOptions:drawingContext:wantsTextLineFragments:validatedAttributedString:firstNonRenderedCharacterIndex:foundSoftHyphenAtEOL:enginePathUsed:] + 1142
7   UIFoundation                        0x000000011b0c9a67 __NSStringDrawingEngine + 5999
8   UIFoundation                        0x000000011b0c64bf _NSStringDrawingCore + 173
9   UIFoundation                        0x000000011b0cac82 -[NSAttributedString(NSExtendedStringDrawing) drawWithRect:options:context:] + 456
10  UIKitCore                           0x00000001197b3ea4 -[UILabel _drawTextInRect:baselineCalculationOnly:] + 3783
11  UIKitCore                           0x00000001197b0dc8 -[UILabel drawTextInRect:] + 1051
12  UIKitCore                           0x00000001197b4169 -[UILabel drawRect:] + 71
13  UIKitCore                           0x00000001198656f3 -[UIView(CALayerDelegate) drawLayer:inContext:] + 632
14  QuartzCore                          0x0000000104fbb6bf -[CALayer drawInContext:] + 285
15  QuartzCore                          0x0000000104e85743 CABackingStoreUpdate_ + 190
16  QuartzCore                          0x0000000104fc40e9 ___ZN2CA5Layer8display_Ev_block_invoke + 53
17  QuartzCore                          0x0000000104fbb042 -[CALayer _display] + 2022
18  QuartzCore                          0x0000000104fcda80 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 502
19  QuartzCore                          0x0000000104f14848 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
20  QuartzCore                          0x0000000104f49b51 _ZN2CA11Transaction6commitEv + 643
21  UIKitCore                           0x000000011937a3f4 _UIApplicationFlushRunLoopCATransactionIfTooLate + 104
22  UIKitCore                           0x000000011941d57a __handleEventQueueInternal + 6902
23  CoreFoundation                      0x0000000106769471 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24  CoreFoundation                      0x000000010676939c __CFRunLoopDoSource0 + 76
25  CoreFoundation                      0x0000000106768b74 __CFRunLoopDoSources0 + 180
26  CoreFoundation                      0x000000010676387f __CFRunLoopRun + 1263
27  CoreFoundation                      0x0000000106763066 CFRunLoopRunSpecific + 438
28  GraphicsServices                    0x000000010ac59bb0 GSEventRunModal + 65
29  UIKitCore                           0x0000000119380d4d UIApplicationMain + 1621
30  Fab4Everyday                        0x00000001026efb3b main + 75
31  libdyld.dylib                       0x000000010c2e7c25 start + 1
32  ???                                 0x0000000000000001 0x0 + 1

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

Upvotes: 1

Views: 188

Answers (1)

daddyhuzzah
daddyhuzzah

Reputation: 21

I fixed the problem in what I think is a non-sensical way. While I made changes to many functions, simplified, etc., the one change I made was to give every view/nav controller a storyboard ID and restoration ID. Now everything was.

Upvotes: 0

Related Questions