8

Xcode 11 with iOS 13 now launches with a slightly different setup from before, moving many functions from the AppDelegate.m file into a new file called SceneDelegate.m - deleting the Main.storyboard and setting the root view controller in AppDelegate is no longer an option, leading to the error below:

-[AppDelegate window]: unrecognized selector sent to instance

enter image description here

How to continue building new projects without storyboard?

Johnny Rockex
  • 4,136
  • 3
  • 35
  • 55

6 Answers6

28

Check this post: Xcode 11.3 | [Remove Storyboard from project][1]

Step 1: Delete Storyboard

After successfully creation new project, navigate to Project Navigator found in left corner of the Xcode window. We need to delete Main.storyboard file from here.

Step 2: Remove Main Interface

Then move to General Tab and delete your Main Interface link here and hit enter.

Step 3: Delete Storyboard file from Info.plist.

Remove Main.storyboard from Info.plist.

Step 4: Make your app run without Storyboard.

If you have seen carefully in Project Navigator you can see 2 delegate files AppDelegate.swift and SceneDelegate.swift. So in previous Xcode’s we have seen there was UIWindow variable present in AppDelegate.swift and now for Xcode 11 it’s gone. Now you can see window variable in SceneDelegate.swift file. In this file you need to make configuration for you load you xib file.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(frame: windowScene.coordinateSpace.bounds)
    window?.windowScene = windowScene
    window?.rootViewController = ViewController()
    window?.makeKeyAndVisible()
}

That’s it! Now you can run your App without Storyboard.

GitHub sample project

dev.doc
  • 569
  • 3
  • 12
  • 18
Sapar Friday
  • 652
  • 8
  • 7
  • 1
    As of Xcode 14, you must also clear Target → Build Settings → "UIKit Main Storyboard File Base Name". – DanubePM Oct 18 '22 at 20:21
4

Im running Xcode 11.4 and got this working in Objective-C
Step 1: Delete Storyboard
Step 2: Remove Main interface
Step 3: Delete storyboard in info.plist
Step 4: With the new addition of SceneDelegate in Xcode11
I added this to the -(void)scene method after all the comments:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.windowScene = (UIWindowScene *)scene;
self.window.rootViewController = [[UINavigationController alloc]
                     initWithRootViewController:ViewController.new];
//self.window.rootViewController = [[ViewController alloc]init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

As You can see this embeds the viewController inside a navigationController, but below is the setting for without one.
Hope this helps

  • Thank you! I was trying to set the window scene when initializing the window in obj-c rather than setting the property later but the keyboard wasn't appearing when tapping on text fields. This fixed it for me. – Jon C Jul 22 '20 at 20:50
2

All of the answers above should work for you. 1. Delete Main.storyboard 2. Delete references to Main.storyboard in info.plist 3. Add window to SceneDelegate 4. set up rootviewcontroller

If you need a visual, see the video I have linked as a source.

Source: https://youtu.be/2oo0tO1E9ys

shmathur
  • 59
  • 2
1

Answer is already in question: you need add window property. Xcode 11 doesn't generate it.

Cy-4AH
  • 4,370
  • 2
  • 15
  • 22
1

You could still use this empty application template in Xcode 11.

Itachi
  • 5,777
  • 2
  • 37
  • 69
1

Step 1:

In SceneDelegate.swift:

replace this line:

guard let _ = (scene as? UIWindowScene) else { return }

with this:

guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = ViewController()
window?.backgroundColor = .systemBackground // optional
window?.makeKeyAndVisible()

Step 2: Delete these two entries from info.plist:

  • "Storyboard Name" under "Application Scene Manifest ..."

  • "Main storyboard file base name"

enter image description here

Step 3. Delete the Main.storyboard file

Paul
  • 115
  • 2
  • 10