How to create an Empty Application in Xcode without Storyboard

IosXcodeStoryboardXcode6

Ios Problem Overview


Xcode6 has removed the Empty Application template when creating a new project. How can we create an empty application (without Storyboard) in Xcode6 and above, like in earlier versions?

Ios Solutions


Solution 1 - Ios

There is no option in XCode6 and above versions for directly creating an Empty Application as in XCode5 and earlier. But still we can create an application without Storyboard by following these steps:

  1. Create a Single View Application.
  2. Remove Main.storyboard and LaunchScreen.xib (select them, right-click, and choose to either remove them from the project, or delete them completely).
  3. Remove "Main storyboard file base name" and "Launch screen interface file base name" entries in Info.plist file.
  4. Open AppDelegate.m, and edit applicationDidFinishLaunchingWithOptions so that it looks like this:

Swift 3 and above:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
    {
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        self.window?.makeKeyAndVisible()
        return true
    }

Swift 2.x:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
    {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        self.window?.backgroundColor = UIColor.whiteColor()
        self.window?.makeKeyAndVisible()
        return true
    }

Objective-C:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.rootViewController = [[ViewController alloc] init];
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }

Solution 2 - Ios

A simple approach would be to copy the XCode 5's Empty Application template to XCode's templates directory.

You can download XCode 5's Empty Application template from here, then unzip it and copy to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application directory.

P.S this approach works with swift as well!

Edit
As suggested by @harrisg in a comment below, You can place the above mentioned template in ~/Library/Developer/Xcode/Templates/Project Templates/iOS/Application/ folder so that it may be available even if Xcode gets updated.
And if there is no such directory present, then you might have to create this directory structure: Templates/Project Templates/iOS/Application/ in ~/Library/Developer/Xcode/

Using this simple approach i'm able to create an Empty Application in XCode 6. (Screenshot attached below)

Xcode Empty Application Template Hope this helps!

Solution 3 - Ios

There are a few more steps that you need to do:

  1. To add a prefix file. (If you need it)
  2. To add a default launch image, otherwise the app size will be 320x480 on iPhone 5.

So here is a full tutorial:

  1. remove Main.storyboard file

  2. remove LaunchScreen.xib file

  3. remove "Main storyboard file base name" property in Info.plist

  4. remove "Launch screen interface file base name" property in Info.plist

  5. add "[app name]-Prefix.pch" file to supporting files with contents:

     #import <Availability.h>
    
     #ifndef __IPHONE_3_0
     #warning "This project uses features only available in iOS SDK 3.0 and later."
     #endif
    
     #ifdef __OBJC__
     #import <UIKit/UIKit.h>
     #import <Foundation/Foundation.h>
     #endif
    
  6. add "$SRCROOT/$PROJECT_NAME/[pch file name]" to project settings -> Build Settings -> Apple LLVM 6.0 - Language -> "Prefix Header"

  7. add "YES" to to project settings -> Build Settings -> Apple LLVM 6.0 - Language -> "Precompile Prefix Header"

  8. open "Image.xcassets" and add LaunchImage

  9. build the project, then there will be a warning about missing default launch image, just press on the warning and select to add the default, this will add "Default-568h@2x" OR - If you want to use splash images from "Images.xcassets", go to the project settings -> TARGETS -> General -> in "Launch Images Source" choose to use asset catalog, it will create a new one, you can choose then, which to use as asset catalog from the existing.

  10. implement application:didFinishLaunchingWithOptions: method:

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    return YES;
    

Solution 4 - Ios

Akhils answer is totally correct. For those of us using Swift, it would be like this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    self.window?.backgroundColor = UIColor.whiteColor()
    self.window?.makeKeyAndVisible()
    return true
}

Solution 5 - Ios

Xcode 9.3.1 and Swift 4

  1. First of all you need delete Main.storyboard in Project navigator menu.

  2. Then delete row Main storyboard file base name in Info.plist.

  3. And don't forgot delete cell Main Interface (just remove Main) in your Project Target - General - Deployment Info.

  4. After that steps go to AppDelegate.swift and in function didFinishLaunchingWithOptions write the next:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
    
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        window?.rootViewController = UINavigationController(rootViewController: ViewController())
    
        return true
    }
    

Xcode 11.2.1 and Swift 5

  1. First of all you need delete Main.storyboard in Project navigator menu.

  2. Then delete row Main storyboard file base name in Info.plist.

  3. And don't forgot delete cell Main Interface (just remove Main) in your Project Target - General - Deployment Info.

  4. This step is important and it was not in previous versions of Xcode and Swift. In Info.plist go to: Application Scene ManifestScene ConfigurationApplication Session RoleItem 0 and delete here Storyboard.name row.

  5. After that steps go to SceneDelegate and in function scene write the next:

     func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
         // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
         // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
         // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
         guard let windowScene = (scene as? UIWindowScene) else { return }
     
         window = UIWindow(frame: windowScene.coordinateSpace.bounds)
         window?.windowScene = windowScene
         window?.rootViewController = ViewController()
         window?.makeKeyAndVisible()
     }
    

Solution 6 - Ios

Update: Swift 5 and iOS 13:

  1. Create a Single View Application.
  2. Delete Main.storyboard (right-click and delete).
  3. Delete "Storyboard Name" from the default scene configuration in the Info.plist file: enter image description here
  4. Open SceneDelegate.swift and change func scene from:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let _ = (scene as? UIWindowScene) else { return }
}

to

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).x
        
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = ViewController()
        self.window = window
        window.makeKeyAndVisible()
    }
}

Solution 7 - Ios

There is one more step that you need to do:

1)remove Main storyboard file base name in plist file

//AppDelegate.h


@property (strong, nonatomic) UIViewController *viewController;
@property (strong, nonatomic) UINavigationController *nav;

//AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {`enter code here`
    // Override point for customization after application launch.
    
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    
    UIWindow *window = [[UIWindow alloc] initWithFrame:screenBounds];
    
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    
    
    self.viewController = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    
    self.nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    
    [window setRootViewController:  self.nav];
    
    [window makeKeyAndVisible];
    
    [self setWindow:window];
    
    return YES;
}

Solution 8 - Ios

I have the original Empty Application template which was used in Xcode versions prior to Xcode 6. I have uploaded it here.

You can either download it and paste it in the Xcode template directory manually or install it using the package manager for Xcode, Alcatraz. Just search for Xcode Empty Application.

Solution 9 - Ios

Remove the Main.storyboard file

This can simply be deleted.

Update the ProjectName-Info.plist file

Remove the Main storyboard base file name key.

Create a nib file and link to the project’s view controller

1.Create a nib file (File –> New –> File –> View)

2.Update the File's Owner's class to whatever the project’s view controller is called

3.Link the File's Owner's view outlet to the view object in the nib file

Update the app delegate

1.Import the project’s view controller’s header file

2.Update the application:didFinishLaunchingWithOptions: method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

Solution 10 - Ios

For Xcode 8 and Swift 3. Just delete the .storyboard file, it will automatically delete the corresponding reference from your .plist and in your AppDelegate.swift add the following code.

> let initialViewController = UIViewController() initialViewController.view.backgroundColor = .white window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = initialViewController window?.makeKeyAndVisible()

You can write your own custom ViewCountroller and use in that in AppDelegate.swift as your self.window?.rootViewController, just replace the UIViewController with your own ViewController in the above code.

Solution 11 - Ios

I am using XCode6 Beta & I searched for another solution of this problem by adding Empty template from XCode5.x.x to XCode6 Beta.

For this right click on XCode5.x.x in Applications click 'Show Package Content' and copy 'Empty Application.xctemplate' from given path

Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application

Now quit the Window & open given path for XCode6

Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application/

Paste 'Empty Application.xctemplate' inside Application folder. Now restart XCode6 by quiting & create new project. You will get 'Empty Application' option.

Now when I am creating new Empty project,a .pch file automatically added in project (Which we have to add manually in XCode6)

Hope it will work

Solution 12 - Ios

Yes, Or just use one of the previous Beta to create it, and continue on the latest version after.

Solution 13 - Ios

You can create your own project template for Xcode. For your request, you can use template on this site:

https://github.com/elprup/xcode7-project-template

Solution 14 - Ios

Others have already explained how to get rid of the storyboard, so I will skip on that one here. This is how I prefer to do it in my code with less optional chaining (written in Swift 3.1):

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
	
	let window = UIWindow(frame: UIScreen.main.bounds)
	window.backgroundColor = .white
	window.rootViewController = MyRootViewController()
	window.makeKeyAndVisible()
	self.window = window
	
	return true
}

Solution 15 - Ios

update on Xcode 11 and ios 13. After you have everything set but still see a black screen, it's because the life cycle is handled by UISceneDelegate and when you create a new project, it will auto-generate UISceneDelegate.m and UISceneDelegate.h. To go back to the old days before we get used to UISceneDelegate. following steps could help:

  1. delete Application Scene Manifest in plist.

  2. delete Application Scene Manifest.h and Application Scene Manifest.m

  3. delete code under #pragma mark - UISceneSession lifecycle in APPdelegate.m

  4. add @property (strong, nonatomic) UIWindow * window; in APPdelegate.h

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAkhil K CView Question on Stackoverflow
Solution 1 - IosAkhil K CView Answer on Stackoverflow
Solution 2 - IosS1LENT WARRIORView Answer on Stackoverflow
Solution 3 - IosNikitaView Answer on Stackoverflow
Solution 4 - IosNils HottView Answer on Stackoverflow
Solution 5 - IosiAleksandrView Answer on Stackoverflow
Solution 6 - IosEric WienerView Answer on Stackoverflow
Solution 7 - IosBhushan_pawarView Answer on Stackoverflow
Solution 8 - IosIsuruView Answer on Stackoverflow
Solution 9 - IosBhargavView Answer on Stackoverflow
Solution 10 - IosVakasView Answer on Stackoverflow
Solution 11 - IosGagan_iOSView Answer on Stackoverflow
Solution 12 - IosP1kachuView Answer on Stackoverflow
Solution 13 - IoselprupView Answer on Stackoverflow
Solution 14 - IosDevAndArtistView Answer on Stackoverflow
Solution 15 - Iosxiaofeng zhouView Answer on Stackoverflow