I have this code var window = UIWindow()
in my AppDelegate. My app is working fine before. After I updated my XCode to 6.3, I can no longer run my iOS app in simulator as I am getting the error
type of 'window' has different optionality than required by protocol 'uiapplicationdelegate'
Thanks for all your contributions. I am not really sure about the reason why suddenly my code window
declaration is no longer working. To fix it, I used the answer from here: https://stackoverflow.com/a/25482567/2445717
I revert the declarion of window to the default: 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()
}
In Swift 2, AppDelegate have:
var window: UIWindow?
instead of
var window: UIWindow
because it should be nil
You can use a lazy var to make code simply
lazy var window: UIWindow? = {
let win = UIWindow(frame: UIScreen.mainScreen().bounds)
win.backgroundColor = UIColor.whiteColor()
win.rootViewController = UINavigationController(rootViewController: self.authViewController)
return win
}()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With