Xcode Programmatic Project Setup

Xcode version 12.01

Programmatic constraints is a way of laying out and constraining views as opposed to using Storyboards. While more intimidating at first, programmatic constraints can be a faster way to create user interfaces. It just takes some practice.

When creating a new Xcode project, there isn’t a nice preset dropdown option that will configure a boiler plate programmatic project for us.

(You could make your own! Check out: BrianVoong // verebes1)

Here are 5 steps to get your programmatic project set up and leave storyboards behind like a bad ex.

1. TRASH THE MAIN.STORYBOARD

Delete and forget it. You deserve better and want some consistent contraints in your life.

(Swift UI takeover is coming…)

2. Info.plist

Remember Main.Storyboard? Me neither. Delete it’s baggage:

  • Storyboard Name
  • Main storyboard file base name

3. Main Interface: LaunchScreen.storyboard

In your project’s target file set Main Interface to: LaunchScreen.storyboard

While you moved on from your main.storyboard, you’re still cool with their brother LaunchScreen so you keep in touch.

4. SceneDelegate.swift

In SceneDelegate.swift, under the func scene(willConnectTo:) configure the root view controller to be your CustomViewController.

Here are a couple examples of different controllers you would commonly use:

5. CustomViewController.swift

To test if your rootViewController is linked up correctly, go to your ViewController file and change the background color of your view.

We have re-found ourself and can now make changes as we please without IBOutlet’s permission.

Summary

  1. Delete Main.storyboard.
  2. Remove Storyboard Name and Main storyboard file base name from Info.plist.
  3. Set Main Interface to LaunchScreen.storyboard in the target of your project file.
  4. Set the windowScene rootViewController to your CustomViewController in the SceneDelegate.Swift.
  5. Change the background color on your CustomViewController.

mobile software engineer \\\ ☕️💻 📷 https://github.com/leoidiaz