I'm not getting the reason of below error in viewWillTransition function:--
Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value + 0
super.viewWillTransition(to: size, with: coordinator)
view.subviews.forEach { $0.removeFromSuperview() }
let deviceName = UIDevice.current.model
if deviceName == "iPhone" {
UserDefaults.standard.set(size.width, forKey: "RotScreenWidth")
UserDefaults.standard.set(size.height, forKey: "RotScreenHeight")
}
// var text=""
switch UIDevice.current.orientation{
case .portrait:
//text="Portrait"
self.viewDidLoad()
case .portraitUpsideDown:
//text="PortraitUpsideDown"
self.viewDidLoad()
case .landscapeLeft:
//text="LandscapeLeft"
self.viewDidLoad()
case .landscapeRight:
// text="LandscapeRight"
self.viewDidLoad()
default:
//text="Another"
self.viewDidLoad()
}
}
I've found this error from window -> Organiser -> crashes.
NOTE:- I've done all my design programmatically and all my design are loaded from viewDidLoad() . So I need to reload the design when there is device rotation.