The app delegate must implement the window property if it wants to use a main storyboard file swift

60,327

Solution 1

Make sure you have the following property declaration in your AppDelegate class:

var window: UIWindow?

Solution 2

If you run your project on earlier than iOS 13.0, in that case you will face the problem. Because of iOS 13 and later, app launch differently than earlier versions.

  • In iOS 13 and later, use UISceneDelegate objects to respond to life-cycle events in a scene-based app

  • In iOS 12 and earlier, use the UIApplicationDelegate object to respond to life-cycle events.

When you launch the app in iOS 12 and earlier then UIApplicationMain class expect a window property in your AppDelegate class as like SceneDelegate has. So your problem will be solved if you add the following line in your AppDelegate class.

var window: UIWindow?

For Objective-C

@property (strong, nonatomic) UIWindow *window;

You can find more here App's Life Cycle.

Solution 3

Just in case anyone comes across this again and is programming in Objective-C make sure you have this line of code in your AppDelegate.h file:

@property (strong, nonatomic) UIWindow *window;

Solution 4

I have received this error, when I created new project in XCode 11. I have not used SwiftUI. Here are the steps, I have considered to fix this.

  1. Deleted Application Scene Manifest entry from Info.plist
  2. Deleted SceneDelegate.swift file
  3. Deleted all scene related methods in AppDelegate.swift class
  4. added var window: UIWindow? property in AppDelegate.swift class

After these steps, I am able to run the app on version prior to iOS 13.

[EDIT]
Finally, your AppDelegate.swift file should look something like the following.

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

}

Solution 5

Add the following window declaration in Appdelegate file

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window:UIWindow?
    ...

Implementation of this property is required if your app’s Info.plist file contains the UIMainStoryboardFile key. The default value of this synthesized property is nil, which causes the app to create a generic UIWindow object and assign it to the property. If you want to provide a custom window for your app, you must implement the getter method of this property and use it to create and return your custom window.

Share:
60,327

Related videos on Youtube

Ethan Marcus
Author by

Ethan Marcus

Updated on April 25, 2022

Comments

  • Ethan Marcus
    Ethan Marcus about 2 years

    I have just developed an app, but when running in the simulator the debugger console says:

    The app delegate must implement the window property if it wants to use a main storyboard file.

    I have an app delegate file. What does the message mean, and how can I get my app working?

    • clearlight
      clearlight about 9 years
      That question is very hard to understand. Can you try to improve it?
    • lchamp
      lchamp about 9 years
      Not sure what you're trying to do. But from what you provided, I may ask : did you have the var window: UIWindow? property in your AppDelegate class ?
    • brainray
      brainray over 8 years
      This is the error message that Xcode spits out in the console
    • Aashish1aug
      Aashish1aug about 6 years
      Check your appDelegate class, It should be the subclass of UIResponder. If your app-delegate is subclass of UIApplication. Please check it once again.
    • Abhishek Maurya
      Abhishek Maurya over 2 years
      I encounter this issue today for the first time took me more than 2 hours to fix, but I think I got the final fix. Mentioned here stackoverflow.com/a/71230252/11690901
  • Raviteja Mathangi
    Raviteja Mathangi over 4 years
    I wrote this line in AppDelegate class and i changed Main Interface (Target ->General ->Main Interface = Main.storyboard. Still i am getting same .Xcode version is 11.0 .How to fix it
  • Muzahid
    Muzahid over 4 years
    Could you please share your crush log?
  • Raviteja Mathangi
    Raviteja Mathangi over 4 years
    input file 'CustomTabBar.swift' was modified during the build Command CompileSwiftSources failed with a nonzero exit code
  • Muzahid
    Muzahid over 4 years
    But your log says you modified your code when building your project. Clean your build folder (Command+Shif+K). Hope your problem will be resloved.
  • Raviteja Mathangi
    Raviteja Mathangi over 4 years
    Yeah it's done ..May be Xcode 11 is some slow in device .Thanks
  • W S
    W S over 4 years
    For Objective-C, add the property to the AppDelegate.h file.
  • Abhijith Brumal
    Abhijith Brumal over 4 years
    If you're not using swiftUI this should be the correct answer worked for me. Thanks @Sarvan
  • rgkobashi
    rgkobashi over 4 years
    yep, this should be the right answer, with the explanation of why it is needed :D thanks!
  • Sazzad Hissain Khan
    Sazzad Hissain Khan over 4 years
    How come just declaring a property resolved the issue! Developers are crazy indeed.
  • WestCoastProjects
    WestCoastProjects about 4 years
    Fair enough - except mine does and still has the error. I'll upvote since it is at least applicable.
  • Alessandro Ornano
    Alessandro Ornano over 3 years
    This is a workaround to make a regression to the old AppDelegate session, not a solution.
  • Naresh
    Naresh over 2 years
    Very nice explanation and this solution is working fine in Xcode 13 & iOS 15.