Delete Storyboard (Xcode 14 Edition)
I do this all the time!
--
Difficulty: Beginner | Easy | Normal | Challenging
I’ve written an article detailing the advantages of using loadView()
instead of storyboards.
You know what, I love using programmatic interfaces while making my Apps. I wrote an article about removing them, but since I tend to do this so often I thought this
This article has been developed using Xcode 14.2 and Swift 5.7.2
Prerequisites:
This article has been written to allow you to write code using loadView() like in my article featuring Playgrounds, and one suitable for Xcode versions previous to 14. In this article, you’ll be expected to be aware of how to make a Single View Application in Swift.
Getting Started
Once you’ve created a Single View Application, you’re presented with something like the following image:
What’s the problem? Can you see on the left-hand side? Beside your projects? We have a storyboard there — and the whole point is we aren’t going to be using it. If we delete it, we won’t get any further than a blank screen on the simulator followed by an **NSInvalidArgumentException**.
That’s not great at all.
Step by Step
I’m going to arrange my classes much like I did in the loadView() article.
The classes
I can list the code for these classes (now I prefer to download these from the repo, but there you go), but I’m leaving the explanation with the original article, as these are basically just created to give us some code to test during the process. In other words, don’t panic!
ViewController
final class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func loadView() {
let view = ButtonView()
view.button.addTarget(self, action: #selector(buttonDidTap), for: .touchUpInside)…