pointfree.co

Previous video

Concise Forms: SwiftUI

Downloads

Next video

Locked

Unlock This Video

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

Sign up

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

Read the original on pointfree.co ↗