Yugal Jindle Yugal Jindle - 3 months ago 16
iOS Question

How does Xcode sets rootViewController implicitly via storyboard?

Xcode with the project file and Info.plist locates the main.storyboard and finds out the initial ViewController. But I was hoping to see some boiler plate code in AppDelegate for the ViewController.

AppDelegate looks blank: (No reference to ViewController)

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;



StoryBoard is xml:
enter image description here


Does Xcode what magic code to refer storyboard xml and find the controller ?

After the compilation, main() brings up AppDelegate which should either have reference to ViewController directly or have a proxy storyboard object to get to the ViewController.

What am I missing ?


I think my book (which you already found) explains it fully. main calls UIApplicationMain() and it follows certain rules. If you have a main storyboard designated in your Info.plist — and you do — then:

  • UIApplication pulls the initial view controller instance (the one with the Entry Point arrow) out of the storyboard. That's the ViewController instance.

  • It also instantiates the UIApplication class.

  • It also instantiates the app delegate class (specified in the UIApplicationMain call), and assigns it to the UIApplication's delegate property.

  • It makes a window and assigns it to the app delegate's window property, then assigns that view controller to the window's rootViewController property.

  • Then it shows the window (and calls applicationDidFinishLaunching... on the app delegate`).

That completely explains the launch process.