The window type has a different option than is required by the uiapplicationdelegate protocol after upgrading Xcode to 6.3

I have this code var window = UIWindow() in my AppDelegate application. My application is working fine. After I updated my Xcode to 6.3, I can no longer run the iOS application in the simulator, as I get an error

the window type has different options than required by the 'Uiapplicationdelegate' protocol

+5
source share
3 answers

Thanks for all your contributions. I'm not quite sure why my ad window code is suddenly no longer working. To fix this, I used the answer from here: fooobar.com/questions/59349 / ...

I return the default window declaration: var window: UIWindow?

and then used the code below for didFinishLaunchingWithOptions

  window = UIWindow(frame: UIScreen.mainScreen().bounds) if let window = window { window.backgroundColor = UIColor.whiteColor() window.rootViewController = ViewController() window.makeKeyAndVisible() } 
+1
source

If you press cmd on the word UIApplicationDelegate in the class definition of your code, you will open the protocol definition. I suspect you are using this call:

  func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) {...} 

and this may have changed in Swift 1.2, but does not seem to have been widely documented. If you wrote instead

 func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) {...} 

then you will get the error message that you are reporting.

This particular problem has not been fixed by the automated program that Daniel Nagy mentions - I ran into a similar problem.

If you provided this optional function, just add ? after the UIWindow in the function definition.

0
source

In Swift 2, AppDelegate have:

 var window: UIWindow? 

instead

 var window: UIWindow 

because he must be nil

You can use lazy var to make the code just

 lazy var window: UIWindow? = { let win = UIWindow(frame: UIScreen.mainScreen().bounds) win.backgroundColor = UIColor.whiteColor() win.rootViewController = UINavigationController(rootViewController: self.authViewController) return win }() 
0
source

All Articles