iOS UIStoryboard Getting an instance of UIStoryboard programmatically

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example


SWIFT:

Getting an instance of UIStoryboard programmatically can be done as follows:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

where:

  • name => the name of the storyboard without the extension
  • bundle => the bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application.

For example, you can use the instance created above to access a certain UIViewController instantiated within that storyboard:

   let viewController = storyboard.instantiateViewController(withIdentifier: "yourIdentifier")

OBJECTIVE-C:

Getting an instance of UIStoryboard in Objective-C can be done as follows:

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

Example of accessing UIViewController instantiated within that storyboard:

MyViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifier"];


Got any iOS Question?