Let's add some code

Let's get our hands dirty with some code. We can try using the template panel to implement a switch statement and a for loop. How do we do this?

  1. Let's open the Utilities panel. To do so, use the topmost right icon on the toolbar or simply press Option + cmd + 1.
  2. Then select the second tab in the bottom part {} to open the code snippets library.
  3. Next, type the following in the filter field—Swift switch.
  4. You should see just a single item.
  5. Drag that item to the editor:
  1. Once you drop it,  you will see the switch structure with a few placeholders to fill in.
  2. Try to fill the gaps, so the switch looks something like this:

Get Learn Swift by Building Applications 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.