Issue
I started taking a look of the new Swift
on Xcode 6
, and I tried some demo projects and tutorials. Now I am stuck at:
Instantiating and then presenting a viewController
from a specific storyboard
Objective-C Solution
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"myStoryboardName" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"myVCID"];
[self presentViewController:vc animated:YES completion:nil];
How to achieve this on Swift?
Swift 4.2 updated code is
This worked fine for me when i put it in AppDelegate
If you want to present it modally, you should have something like bellow:
For people using @akashivskyy's answer to instantiate
UIViewController
and are having the exception:Quick tip:
Manually implement
required init?(coder aDecoder: NSCoder)
at your destinationUIViewController
that you are trying to instantiateIf you need more description please refer to my answer here
Swift 3
I created a library that will handle this much more easier with better syntax:
https://github.com/Jasperav/Storyboardable
Just change Storyboard.swift and let the
ViewControllers
conform toStoryboardable
.