Skip to content

Instantly share code, notes, and snippets.

@ishaq
Last active September 6, 2018 10:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ishaq/7749853 to your computer and use it in GitHub Desktop.
Save ishaq/7749853 to your computer and use it in GitHub Desktop.
iOS: load main interface programmatically
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = nil;
BOOL showLogin = NO;
if(showLogin == NO)
{
// mainStoryboard method looks like:
// return [UIStoryboard storyboardWithName:@"Main" bundle:nil];
mainStoryboard = [UIStoryboard mainStoryboard];
}
else
{
mainStoryboard = [UIStoryboard loginStoryboard];
}
UIViewController *rootController = [mainStoryboard instantiateInitialViewController];
NSAssert(rootController, @"no user interface, what is this? a web service??");
self.window.rootViewController = rootController;
[self.window makeKeyAndVisible];
return YES;
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var mainStoryboard: UIStoryboard? = nil
let showTutorial = true
if(showTutorial) {
mainStoryboard = UIStoryboard.tutorialStoryboard()
}
else {
// mainStoryboard method looks like:
// return UIStoryboard(name: "Main", bundle: nil)
mainStoryboard = UIStoryboard.mainStoryboard()
}
let rootController = mainStoryboard!.instantiateInitialViewController()
assert(rootController != nil, "no user interface, must be the D day")
self.window?.rootViewController = rootController
self.window?.makeKeyAndVisible()
return true
}
@harvdogg
Copy link

harvdogg commented Apr 4, 2018

Note that as of Swift 4 that UIScreen.mainScreen().bounds (line 2) has been renamed to UIScreen.main.bounds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment