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, additional 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
:a. Press Command () + N.
b. Select SwiftUI View.
c. Click Next.
d. Name the view
signUpView
.e. Click Finish.
- In
signUpView
, declare and initialize the@State
variables that will be used in...