Optionals

Introduction

You already understand how to use typical data types such as Int, Double, String, and Bool.

You have already built – or will build soon – applications that accept user input in these ways:

  1. As an Int via the Stepper structure
  2. As a Double via the Slider structure.

Steppers and sliders prevent the user from providing invalid input.

This is very helpful, however, in the case of:

Sometimes, it would be preferable to accept "free form" or typed input from the user.

What happens, though, when invalid input is received from a user?

For example, our app might expect numeric input – but the user could type fifty rather than 50.

This is when the notion of an optional data type becomes useful.

Getting started

Please download a ZIP file of this project:

Screenshot 2024-01-09 at 8.11.04 PM.png|500

Double-click to expand the ZIP file in your Downloads folder:

Screenshot 2024-01-09 at 8.12.16 PM.png|500

Move the new folder to your Computer Studies folder:

Screenshot 2024-01-09 at 8.12.40 PM.png|500

Double-click to open the folder:

Screenshot 2024-01-09 at 8.13.07 PM.png|500

Double-click the blue .xcodeproj file:

Screenshot 2024-01-09 at 8.13.20 PM.png|500

You will see the following dialog – choose Trust and Open:

Screenshot 2024-01-09 at 8.13.36 PM.png|250

You will see the opening page of the playground. Read the introduction carefully. When you ready, tap the blue link at the bottom of the page to advance:

Screenshot 2024-01-09 at 8.03.15 PM.png

Try each page of the playground by following instructions given, while taking notes in your black paper notebook.

Take your time – read for understanding – write down your responses to the questions posed in your black book.

When you are done – summarize in writing what you have learned in your Notion post for today – as well as any questions you have.

Important

Be sure to include several screenshots showing your progress as you completed the playground.