I have added a NavigationController in the StoryBoard and made it the initial viewController. How do I get access to the NavigationController in the appDelegate. Ctrl-drag from navigationController to AppDelegate does not create an outlet.
            Asked
            
        
        
            Active
            
        
            Viewed 2.3k times
        
    17
            
            
        - 
                    2If it's your initial view controller you can access it through `self.window.rootViewController` – spassas Jul 31 '14 at 08:14
2 Answers
33
            In didFinishLaunchingWithOptions:
let navigationController = application.windows[0].rootViewController as! UINavigationController
 
    
    
        Jayprakash Dubey
        
- 35,723
- 18
- 170
- 177
 
    
    
        zisoft
        
- 22,770
- 10
- 62
- 73
- 
                    9Getting this SIGBART error : Could not cast value of type 'SwiftControlsTest.ViewController' (0x1006303f0) to 'UINavigationController' (0x101ecb670). – Jayprakash Dubey Oct 14 '15 at 06:42
- 
                    That's because you don't have a navigation controller set as the root view controller of your application. Your root view controller is a `SwiftControlsTest.ViewController` – Danny Bravo Apr 20 '20 at 06:35
2
            
            
        In custom functions use like this:
let navigationController = self.window?.rootViewController as! UINavigationController
 
    
    
        Anil Kumar
        
- 1,830
- 15
- 24
 
    