The app delegate must implement the window property if it wants to use a main storyboard file swift
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 appIn 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.
- Deleted
Application Scene Manifest
entry fromInfo.plist
- Deleted
SceneDelegate.swift
file - Deleted all scene related methods in
AppDelegate.swift
class - added
var window: UIWindow?
property inAppDelegate.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.
Related videos on Youtube
![Ethan Marcus](https://lh3.googleusercontent.com/-n27dGlsVWew/AAAAAAAAAAI/AAAAAAAAAFo/8CmpVoobPm4/photo.jpg?sz=256)
Ethan Marcus
Updated on April 25, 2022Comments
-
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 about 9 yearsThat question is very hard to understand. Can you try to improve it?
-
lchamp about 9 yearsNot 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 over 8 yearsThis is the error message that Xcode spits out in the console
-
Aashish1aug about 6 yearsCheck 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 over 2 yearsI 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 over 4 yearsI 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 over 4 yearsCould you please share your crush log?
-
Raviteja Mathangi over 4 yearsinput file 'CustomTabBar.swift' was modified during the build Command CompileSwiftSources failed with a nonzero exit code
-
Muzahid over 4 yearsBut 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 over 4 yearsYeah it's done ..May be Xcode 11 is some slow in device .Thanks
-
W S over 4 yearsFor Objective-C, add the property to the AppDelegate.h file.
-
Abhijith Brumal over 4 yearsIf you're not using swiftUI this should be the correct answer worked for me. Thanks @Sarvan
-
rgkobashi over 4 yearsyep, this should be the right answer, with the explanation of why it is needed :D thanks!
-
Sazzad Hissain Khan over 4 yearsHow come just declaring a property resolved the issue! Developers are crazy indeed.
-
WestCoastProjects about 4 yearsFair enough - except mine does and still has the error. I'll upvote since it is at least applicable.
-
Alessandro Ornano over 3 yearsThis is a workaround to make a regression to the old AppDelegate session, not a solution.
-
Naresh over 2 yearsVery nice explanation and this solution is working fine in
Xcode 13 & iOS 15
.