Showing and hiding sections in forms
Forms provide a means of getting information from the user. Users get discouraged when completing very long forms, yet fewer people submitting a form may mean less data for your surveys, fewer signups for your app, or fewer people providing whatever data you're collecting.In this recipe, we will learn how to show/hide the additional address section of a form based on the user's input.
Getting ready
Create a new SwiftUI project named SignUp
.
How to do it…
We will create a signup form with sections for various user inputs. One of the sections, named Previous Address
, will be shown or hidden based on how long the user has lived at their current address. The steps are given here:
- Create a new SwiftUI view called SignUpView:
- Press Command () + N.
- Select SwiftUI View.
- Click Next.
- Name the view SignUpView.
- Click Create.
- In
SignUpView.swift
, above theSignUpView
struct declaration, define the new structAddress
used to hold some data...