How does Xcode load the main storyboard?
Give a look to the UIApplicationMain discussion:
Discussion
This function instantiates the application object from the principal class and instantiates the delegate (if any) from the given class and sets the delegate for the application. It also sets up the main event loop, including the application’s run loop, and begins processing events. If the application’s Info.plist file specifies a main nib file to be loaded, by including the NSMainNibFile key and a valid nib file name for the value, this function loads that nib file.
When UIApplicationMain gets called, a plist file containing all the application info is loaded:
That's how it "understands" that the xib/storyboard file needs to get loaded.
Look at your Target settings for the Project
Notice the Main Storyboard setting.
If you wanted to do this in code yourself, you would do something like.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *vc = [storyboard instantiateInitialViewController];
// Set root view controller and make windows visible
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
In Xcode, the human-readable Info.plist section that determines the main storyboard is:
Main storyboard file base name
In plain text, the key is UIMainStoryboardFile
:
<key>UIMainStoryboardFile</key>
<string>Main</string>
It is started from the UIMainStoryboardFile setting from your info.plist file. Xcode then creates a main window, instantiates your first view controller, and adds it to the window. You can still do this in code similar to the .nib using
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController* initialView = [storyboard instantiateInitialViewController];