Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch new project without a storyboard >= iOS 13 in Xcode 11?

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?

like image 351
Johnny Rockex Avatar asked Nov 01 '19 08:11

Johnny Rockex


2 Answers

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

like image 65
Sapar Friday Avatar answered Nov 20 '22 03:11

Sapar Friday


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

like image 4
CLRmindedProgrammer Avatar answered Nov 20 '22 02:11

CLRmindedProgrammer