Book Image

Swift Cookbook

Book Image

Swift Cookbook

Overview of this book

If you are an experienced Objective-C programmer and are looking for quick solutions to many different coding tasks in Swift, then this book is for you. You are expected to have development experience, though not necessarily with Swift.
Table of Contents (13 chapters)
12
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,...