meismyles / SwiftWebVC

A drop-in inline browser for your Swift iOS app.
MIT License
329 stars 117 forks source link

Crash while navigating in and then back out again quickly #22

Closed awulf closed 7 years ago

awulf commented 7 years ago

When pushing SwiftWebVC on the navigation controller and pressing back again before loading, it can cause SwiftWebVC to crash due to forced unwrapped optionals.

Solution: from line 197 in SwiftWebVC.swift replace

            if !closing {
                if presentingViewController == nil {
                    navigationController!.toolbar.barTintColor = navigationController!.navigationBar.barTintColor
                }
                else {
                    navigationController!.toolbar.barStyle = navigationController!.navigationBar.barStyle
                }
                navigationController!.toolbar.tintColor = navigationController!.navigationBar.tintColor
                toolbarItems = items as? [UIBarButtonItem]
            }

with

            if let navigationController = navigationController, !closing {
                if presentingViewController == nil {
                    navigationController.toolbar.barTintColor = navigationController.navigationBar.barTintColor
                }
                else {
                    navigationController.toolbar.barStyle = navigationController.navigationBar.barStyle
                }
                navigationController.toolbar.tintColor = navigationController.navigationBar.tintColor
                toolbarItems = items as? [UIBarButtonItem]
            }
meismyles commented 7 years ago

Good spot. Thanks for this.