Book Image

Learning Swift

By : Andrew J Wagner
Book Image

Learning Swift

By: Andrew J Wagner

Overview of this book

Table of Contents (18 chapters)
Learning Swift
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Bringing it all together


At this point, you have learned a lot about the basic workings of Swift. Let's take a moment to bring many of these concepts together in a single program. We will also see some new variations on what we learned.

The goal of the program will be to take a list of invitees and television shows and to ask random people to bring a show of each genre and to ask the rest to just bring themselves.

Before we look at the code, there are three small new features that we will use:

  • We will generate a random number

  • We will use a variable to store only true or false

  • We will use a new type of loop called a do-while loop

The most important feature is the ability to generate a random number. To do this, we have to import Foundation Framework. This is the most basic framework made available by Apple. As the name suggests, it forms the foundation for both the frameworks for OS X and iOS.

Foundation includes a function called rand that returns a random number. Computers are not actually capable...