You now have all the skills and knowledge to create an amazing Quiz app to show to your friends or even publish it on the App Store. Let's get started!
Overview
In this project, you will be making a Quiz app. Let's see in a bit more detail what all the app consists of.
- When the app loads, the user sees a Start button to start the quiz.
- The main focus of the Quiz app is to display a question on the screen. The used has two options — True or False — to pick from as his answer.
- Once the user chooses an answer, he is informed whether or not the answer is correct. The user also gets to see his current score.
The buttons displayed on the screen should be based on context. For example, the True and False buttons should only be displayed when a question is asked. The Next button should only be displayed once the user has submitted the answer. (See screenshots above).
Guidance
We encourage you to implement this exercise without any help. As mentioned before, you have all the skills and knowledge required to implement the project from scratch — all the way to loading it on your phone and showing it to your family and friends.
Step-by-step guidance
Here are the steps required to implement the project.
- Start a new Xcode project.
- User Interface
- Think about all the labels and buttons you will need. Add them to your storyboard. Style them as you see fit. (If you get stuck, see the screenshots above.)
- Connect all the UI objects to the code. Note that the buttons will need to be connected twice, once as a function and again as an outlet. The function is called then the button is pressed, and the outlet allows you to change the properties of the button when you need to.
- Logic
- Create two arrays containing the Questions and Answers respectively.
- Think about what all you want to display and update every-time a button is pressed.
- What all need to update when the Start button is pressed? What about True / False? (See the screenshots above if you get stuck). Some things to take care of:
- Update score.
- What labels need to be updated?
- Which buttons need to be hidden? Which buttons need to be made visible?
- What all need to update when the Start button is pressed? (Again, see the screenshots above if you get stuck). Some things to take care of:
- Update question_number.
- What labels need to be updated?
- Which buttons need to be hidden? Which buttons need to be made visible?
- There's an extra special case — what happens when the user answers the last question of the quiz? Add the if .. else statements to handle the case.
- Play the game a few times. Make sure everything's looking good.
- Use Auto-layout to make sure your app looks good on different screen sizes.
- Optionally, add hundreds of questions in your "question bank". When the user presses the Start button, choose 10 questions randomly. That way, every-time the user takes the quiz, he gets a new quiz to play.
- Sideload the app onto your phone. Show it to family and friends. Test their knowledge!
Congratulations
If you were able to complete this, hurray! Pat yourself on the back as you have learnt all the fundamentals of creating an iOS app. Good job!
Solution
Here's the official solution for the project: QuizApp. You can download and open it with Xcode.