Storyboards, scenes, and connections. Add scenes and views. Export an app (macOS) Test the Mac Installer Package. Distribute outside the Mac App Store.

Question or problem with Swift language programming:

Macos App Without Storyboard App

  1. In my previous article, I shared about how we might go about creating a macOS app without a storyboard or.xib file. Now, we will learn how to add a menu bar (mainMenu bar) and toolbar and use.
  2. Useful scripts for macOS March 27, 2020; Creating custom templates for iOS App Development March 25, 2020; Creating iOS Apps without Storyboard – Part 2 September 19, 2019; Creating iOS Apps without Storyboard – Part 1 July 28, 2019.
  3. Maybe the easiest way to mix Storyboard and coding approach. As I pointed out, recreation of NSMenu is a real pain/mess. So, what about keeping Main.storyboard for NSMenu only and code the rest of the components? Create a new macOS app.

I’m rebuilding an app without storyboards and the part of it that I’m having the most trouble with is navigating view-to-view programatically. Few things are written out there which don’t use storyboards, so finding an answer for this has been tough.

My problem is pretty simple. I have my ViewController and my SecondViewController and I want to push from the former to the latter.

In AppDelegate:

Then in ViewController.swift:

Printing self.navigationController returns nil. I’ve tried doing:

var navController = UINavigationController() when the ViewController class is created (but outside of ViewDidLoad, right under the class declaration) and done the push using the navController var but that hasn’t worked.

I’m thinking maybe the solution is to create a navigation controller in App Delegate that the whole app would use, I guess as a global variable?

My hope is that this post can serve many others who are new to Swift and want to remove storyboards from their app.

Thanks for taking a look and for your help.

How to solve the problem:

Solution 1:

In Swift 3

Macos App Without Storyboard Maker


Place this code inside didFinishLaunchingWithOptions method in AppDelegate class.

Solution 2:

In AppDelegate

In ViewController

Hope this helps!