1. UINavigationController *rnc = self.app.window.rootViewController;
I get warning Incompatible pointer types initializing UINavigationController with an expression of type UIViewController
2. UINavigationController *rnc = (UINavigationController *)self.app.window.rootViewController;
The option 1 shows warning "Incompatible pointer types initializing UINavigationController with an expression of type UIViewController" and the option 2 not. Why ? What is a risk if I will not cast like in the option 2 ?
UPDATED
What is a risk of casting UIViewController to UINavigationController ?
rootViewControlleronwindowis not actually an instance ofUINavigationController*(or subclass) and your app crashes at runtime. Swift mitigates this issue by requiring casts in a form ofrnc = window.rootViewController as! UINavigationController. The "cast" (it isn't really cast) will be checked at runtime. - bbum