Chapter 4

Handling User Inputs and Custom Views

IN THIS CHAPTER

check Understanding how to use the various input views

check Understanding how to create custom views using views composition

In this chapter, I introduce you to input views in SwiftUI, which allow you to collect inputs from users. I also explain how you can create your own custom views by grouping all the views available and applying your own layout, so you can reuse them.

Looking at Input Views

Unless you’re writing a Hello World application, your app will involve some sort of user inputs. For example, if you’re writing a conference app, you need the user to select a particular conference from a list of available conferences. If your app requires the user to log in to a secure service, you need the user to enter her credentials (username and password).

In this section, I walk you through some of the input views in SwiftUI.

Tip To try out the various input views in the following sections, you can create a Single View App project and type the code snippets into the ContentView.swift file.

TextField

When you need users to enter some text or numbers, you can use the TextField view, which displays an editable text interface. The following ...

Get SwiftUI For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.