Book Image

Swift Cookbook

By : Cecil Costa, Cecil Costa
Book Image

Swift Cookbook

By: Cecil Costa, Cecil Costa

Overview of this book

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

Quizzing the user


Sometimes, we need to add some icons on our application, but depending on the icon you want, it's not necessary to add an image; you can use Unicode characters. Let's create a quiz app using strings alone.

The idea for this app is to create an app where the user needs to answer a question in 12 seconds. After the last quiz, the app will show to the user his score, such as the number of well-answered and badly-answered questions.

Getting ready

Once we know the concept of this program, let's create a new project and name it Chapter 2 Unicode.

How to do it...

To create a quiz app, follow these steps:

  1. First, let's create a new file called Quiz and add a class with a question to it, with three possible answers and the right answer, as follows:

    class Quiz {
        var question:String
        // First possible answer
        var ①:String
        // second possible answer
        var ②:String
        // third possible answer
        var ③:String
        // Right answer
        var 👌:Int
        
        init(question:String,...