Search code examples
iosobjective-cappdelegatexcode11uiscenedelegate

XCODE 11 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate window]:


Recently i updated to the XCODE 11 and came to know the concepts of SceneDelegate and AppDelegate . This is my simple code for in AppDelegate :

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor yellowColor];
    return YES;
}

But unfortunately its getting crashed on the following line as shown in the Image:

enter image description here

And it shows the following error:

enter image description here

Please help me in resolving the issue which i am facing. Any help will be appreciated.


Solution

  • To Remove Screen Delegates:

    Goto info.plist and remove the selected entry as shown below: enter image description here

    Delete ScreenDelegate.h and ScreenDelegate.m from the project: enter image description here

    Update your AppDelegate.h to:

    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow * window;
    
    @end
    

    And finally, remove the Screen delegates from the AppDelegates class:

    enter image description here

    Hope that helps.

    If you want to use ScreenDelegates you can refer the answer from Asperi