Better Programming

Advice for programmers.

Follow publication

Member-only story

Swift Enums 🤝 Design Systems

Jacob Bartlett
Better Programming
Published in
8 min readMay 23, 2023

I mostly post to Substack these days. Subscribe now to receive non-paywalled, ludicrously in-depth articles on iOS, Swift, and indie projects every 2 weeks.

If you’ve worked on any large development projects, you’ll likely have encountered a design system. A design system is a library that encapsulates your branding into reusable components, colors, fonts, icons, and motifs, to help ensure a consistent style across your products.

In short, they allow us to avoid re-inventing the wheel for every screen of UI design.

Personally, I love working on things to make life easier for my team. Implementing design systems in a clean, straightforward way has huge leverage since your team will work with it every day.

In my career, I’ve implemented various design systems in my apps, and explored many diverse approaches on iOS, such as:

  • UIKit Storyboards and Nibs
  • Programmatically drawn components for each UIKit subclass
  • Protocols to allow composable drawing and animation
  • Enums to declaratively define components

Every approach has its place, but in SwiftUI I’ve found the cleanest, most useable approach by far is defining your components using enums.

As you read through this post, I’ve added many code snippets, but feel free to check out my code from Github and follow along.

The Design System

Let’s say your designer has just sent you a link to their designs — it’s the button component they’ve been working on. It might look something like this:

Generally speaking, any designer worthy of their Figma free tier or Sketch license will have a small set of styles, in a small palette of brand colors, and multiple sizes, icons, and alignments.

You might feel the gears turning in your head as you start to realise why Enums might be a strong approach here.

Define Your Button

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Jacob Bartlett
Jacob Bartlett

Written by Jacob Bartlett

I'm an iOS Engineer in London startups. Every 2 weeks, I'll send you ludicrously in-depth articles about iOS, Swift, tech, and indie projects.

Write a response