SweetAlert-iOS icon indicating copy to clipboard operation
SweetAlert-iOS copied to clipboard

Crashing always

Open stephen-talari opened this issue 10 years ago • 3 comments

Always crashes at line 243
let window: UIWindow = UIApplication.sharedApplication().keyWindow! with error fatal error: unexpectedly found nil while unwrapping an Optional value

i am calling following code in my viewController in viewDidLoad() method SweetAlert().showAlert("Good job!", subTitle: "You clicked the button!", style: AlertStyle.Success)

screen shot 2016-02-04 at 17 54 56 `

stephen-talari avatar Feb 04 '16 12:02 stephen-talari

Same here

oguzkc avatar Mar 13 '16 14:03 oguzkc

@stephen-talari I solved, if you call SweetAlert in ViewDidLoad it crash, i tried in viewdidappear and a button action it worked fine. Happy coding

oguzkc avatar Mar 13 '16 14:03 oguzkc

There is no keyWindow at that point. I would add replace the following

let window: UIWindow = UIApplication.sharedApplication().keyWindow! with:

guard let window: UIWindow = UIApplication.sharedApplication().keyWindow! else { return }

acegreen avatar Jun 04 '16 19:06 acegreen