blog.hal.codes

A smarter way to storyboard

Pure protocol factory for Interface Builder-based views

I’ll admit: I love laying out views in Interface Builder. It’s a bit of a controversial topic but for me, there’s no faster way to build screens for an app. It’s indispensable to be able to see exactly how my views look in IB without recompiling my whole app.

Interface Builder has downsides, no doubt. One of the biggest: multiple developers working on a single Storyboard file can easily cause merge conflicts that are hard or impossible to reconcile. The solution, for me, is to create per-screen Storyboards (really, one for every UIViewController) and handle transitions entirely in code. This approach means that Storyboard views need to be instantiated pretty often in code, which can be a bit ugly:

class MyViewController: UIViewController {
    /// ...
}

let storyboard = UIStoryboard(name: "MyViewController",
                              bundle: Bundle(for: MyViewController.self))
guard let controller = storyboard.instantiateInitialViewController() as? MyViewController else {
    return
}
Continue reading →
👋

Hello world

I made a blog. You’re reading it. I think it’s pretty neat.

This’ll be loosely focused on software development, and in particular iOS development. I’ve been writing software professionally for a few years; I’m still learning, and this blog will help me share that process.

Look for some fresh content soon. I’m hoping to actually be diligent about posting here. There’s an RSS feed if that’s your thing.

Continue reading →