Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7feb2d019000> - In Swift

I  have an iOS project where my entry point is in Swift and the logic is in C++. Hence, I use a ObjectiveC++ bridge in between. I would be creating Ui programmatically using Swift and there is no usage of storyboard file too.

Now, once the 'didFinishLaunching' of the AppDelegate is reached, it calls a Objective C++ method to do the initial setup (core initializations etc). Once things are done, I need to create a UIWindow and attach a ViewController to it.

Below is how the code looks :

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
    NSLog("didFinishLaunching called")
        
    MyObjCppWrapper.mySampleObjCppFunc()

    return true
}

The ObjCppWrapper class's implementation :

@implementation MyObjCppWrapper

+ (void)
mySampleObjCppFunc {
    
    [MySampleCreateWindow CreateWindow];
}

@end

MySampleCreateWindow is a Swift Class which does the work to create the window. Implementation is :

@objc
class MySampleCreateWindow: NSObject {
    
    @objc
    static func CreateWindow () {
        
        var window = UIWindow (frame: UIScreen.main.bounds)
        window.rootViewController = UINavigationController (rootViewController: ViewController ())
        window.makeKeyAndVisible()
        
    }
}

The ViewController just shows a button lets say - code added under 'viewDidLoad'.

When I run this application, I get the below error :

2022-09-21 12:55:51.039805+0530 TWSampleiOSWithoutSB01[47488:4493039] Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7feb2d019000>.

Surprisingly, the code written inside CreateWindow of the MySampleCreateWindow class runs fine if it is pasted inside the didFinishLaunching of the AppDelegate.

Any suggestions on what I am doing wrong or should correct ?

Please note : Many of the solutions given to this similar error were for Obj-C and different scenarios. Some of them seem to be deprecated now.

Unbalanced calls to begin/end appearance transitions for &lt;UINavigationController: 0x7feb2d019000&gt; - In Swift
 
 
Q