Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Xcode load the main storyboard?

When I create a new single view application in Xcode 4.6 using storyboard, we can see that the main function creates a new application using the application delegate like this:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class])); 

However if we look at MyAppDelegate.h and MyAppDelegate.m, there is nowhere in the code that references MainStoryboard.storyboard. This differs from a non-storyboard version where we can find the line of code that loads the nib file programmatically.

So my question is, how does the storyboard get loaded? (where should I poke to find it?)

like image 445
agro1986 Avatar asked May 22 '13 22:05

agro1986


People also ask

What is main storyboard in Xcode?

Storyboarding is a feature built into Xcode that allows both the various screens that comprise an iOS application and the navigation path through those screens to be visually assembled.

Why is Main storyboard not showing up in Xcode?

You have SwiftUI enabled in your project, which does not use storyboards anymore. Your layout is inside the ContentView. swift file. If you do want to work the old way, with storyboards, you should uncheck 'Use SwiftUI' in the project creation screen.

Where is Main storyboard in new Xcode?

storyboard from the Project Navigator (on the left side of Xcode). Once the Storyboard loads in the center pane, use the Object library to add a button to the storyboard.


2 Answers

Look at your Target settings for the Project

enter image description here

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; } 
like image 167
Chris Wagner Avatar answered Sep 25 '22 14:09

Chris Wagner


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:

enter image description here

That's how it "understands" that the xib/storyboard file needs to get loaded.

like image 22
Ramy Al Zuhouri Avatar answered Sep 23 '22 14:09

Ramy Al Zuhouri