pkluz/PKHUD — pull request #10 by kmcgill88 (2014-12-03 04:44:15+00:00)
Title: Initial root view controller fix

I found when setting the initial view controller dynamically PKHUD would kill my app every time due to unwrapping a nil rootViewController. I fixed this by returning a default value if unwrapping fails. This results in a temporary default being set until the rootViewController is non-nil, and the rootViewController's values are used.

Example of setting initialViewController dynamically, initially causing PKHUD to crash my app:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

var purchaseHelper = MyIAPHelper.sharedInstance

setDefaultSettings()

window = UIWindow(frame: UIScreen.mainScreen().bounds)

var storyboard = UIStoryboard(name: "Main", bundle: nil)
var viewController: AnyObject = storyboard.instantiateViewControllerWithIdentifier("MainVC")!
if var root = viewController as? UIViewController {
self.window.rootViewController = (purchaseHelper.productPurchased(ADREMOVAL)) ? root : KMBannerViewController(contentController:root)
}
self.window.makeKeyAndVisible()
return true
}