Concise Forms: SwiftUI

Episode #131 • Jan 18, 2021 • Subscriber-Only

For simple forms, vanilla SwiftUI does a really good job: you can quickly build a form with many components in minimal code and boilerplate. But as a form becomes more complex, SwiftUI stops being so helpful. Let’s explore the problems that emerge and how we can work around them.

Collection
Concise Forms
Concise Forms: SwiftUI
Locked

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Sign in with GitHub

Introduction

Today we are going to focus on a small, but common problem when building applications and that is building forms. By forms we just mean a screen with lots editable fields, such as text fields, toggles, pickers, sliders and more. Such screens are very common for things like settings, log in, sign up and more.

It turns out that for simple, straightforward forms, vanilla SwiftUI does a really good job. There’s basically no boilerplate, and you can handle many form components at once with very little code. However, as the behavior of the form gets more complex, SwiftUI stops being as helpful, and you are forced to do some workarounds that are less than ideal.

These new complexities are what will drive us to look at what the Composable Architecture has to say about forms, but unfortunately the architecture has a few problems of its own when it comes to forms. Most notably, there is a bit of boilerplate involved.

However, it doesn’t have to be that way. Turns out there are some fancy tricks we can employ to regain all the conciseness that SwiftUI gives us while allowing us to build the feature in the Composable Architecture so that we get all of its benefits, such as explicit side effects and testability.

Form view hierarchy


Downloads

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 62 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing