codestergit / SweetAlert-iOS

Live animated Alert View for iOS written in Swift
MIT License
2.05k stars 303 forks source link

Crashing always #30

Open stephen-talari opened 8 years ago

stephen-talari commented 8 years ago

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

`

oguzkc commented 8 years ago

Same here

oguzkc commented 8 years ago

@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

acegreen commented 8 years ago

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 }