How to Create an iPhone Quiz App Using ChatGPT

You don't need to have prior experience in programming code with ChatGPT. In just a few minutes, you can create an iOS quiz app from the ground up. And the best part is: if you have a question, go ahead and ask your robotic personal tutor. Here's how we made an app using ChatGPT.

Justin Gluska

Updated April 23, 2023

a robot coding on a laptop in a dark room, as digital art in 4k

a robot coding on a laptop in a dark room, as digital art in 4k

Reading Time: 7 minutes

Are developers no longer needed? Are we going to replace software developers with ChatGPT?

Eh, not yet. Sorry if I scared you. But it's pretty impressive at what could be done.

ChatGPT is an awesome way of teaching yourself how to code. In just 20 minutes I was able to create an iOS quiz game using nothing but ChatGPT and Xcode. You could do the same.

This isn't a normal tutorial where you just copy what you see. What's great about using ChatGPT is how you can prompt it and ask it questions throughout the journey.

Literally anything you don't understand, ask! It's your very own personal tutor.

Building a Quiz App with ChatGPT and Xcode

I still find myself using ChatGPT every day. Whether it's writing, tutoring, or coding, it pretty much has your back across any field. It's one of those things you go "how did I go without this for so long?"

I never made a quiz app in Swift before. I spent a few minutes thinking of how you make an quiz app (from a birds eye overview). After telling ChatGPT what I was looking for, it was able to walk me through nearly the ENTIRE process. We have a video going over everything in depth:

In this tutorial, we will guide you through the process of creating an engaging iPhone quiz app using the powerful combination of ChatGPT, the Swift programming language, and Xcode (Apples development tool).

By using these three tools, you'll be able to build a simple, yet functional quiz game that gives you the baseline for creating a quiz game.

Currently AI isn't good enough to do it all by yourself, you definitely have to prompt ChatGPT in certain ways. It also can't create it without you sitting in the passenger seat.

Now you don't need to know how to code, or even how to use Xcode (you don't even need to know what Xcode is), but you have to ask ChatGPT questions about everything you want to do. It will give you research into how you should go able tackling your problem (this extends beyond code).

Here are the steps followed to create an iOS quiz app using ChatGPT for assistance:

Setting up your project in Xcode

  1. Create a new project: Launch Xcode on your Mac computer and click "Create a new Xcode project." Choose "Single View Application" as the template for your app.
  2. Name your project: Enter "Quiz app" as the Product Name under Project Options. Make sure to select Swift as the Language option before clicking Next.
  3. Select location: Choose where you want to save your folder on your computer and click Create.

Now head into the ChatGPT and ask it to : Create me a tuple list of 3 questions, each having 4 answer choices

You'll see a long description of random questions and answers get generated, but they should be in the proper order of a tuple (a way of storing and displaying data). If you want more info, ask ChatGPT any types of questions about what it just did.

You'll now have a file with your questions that you've added in your ViewController file (where all the code goes).

Designing User Interface Elements

Now you have to add labels for displaying questions and scores, as well as buttons for answering choices while ensuring proper text wrapping so that content is visually appealing on various screen sizes. At 4:07 in the video, you'll see how we ask ChatGPT to help us do so.

Adding UILabels & UIButtons in Storyboard View Controller

I added some labels, buttons, and text to our screen and connected it to the ViewController.

Start by adding two UILabels: one for the question display and another for the score counter. Then, add four UIButton elements representing multiple-choice answers.

  1. In Xcode's project navigator, click on "Main.storyboard."
  2. Select the Object Library (the "+" icon) at the top-right corner of Xcode.
  3. Type "UILabel" in the search bar and drag two instances onto your View Controller scene.
  4. Type "UIButton" in the search bar and drag four instances onto your View Controller scene.
  5. Arrange these elements according to your desired layout using Auto Layout constraints or Size Classes if needed (Apple's official guide on Auto Layout).

Connecting UI elements to ViewController.swift

The next step is connecting these newly added UI components with their corresponding code counterparts in the ViewController.swift file:

  1. Open the "Assistant Editor" by clicking on the tuxedo icon at the top-right corner of Xcode.
  2. Select ViewController.swift in the editor, so it appears side-by-side with your storyboard.
  3. Control-drag from each UILabel and UIButton to ViewController.swift file, creating IBOutlet connections for labels and IBAction connections for buttons. Be sure to give them descriptive names (e.g., questionLabel, scoreLabel, answerButton1).

Creating the randomQuestion() function

Now that our simple design is done, it's time to ask ChatGPT to create us a randomQuestion() function that selects a random question from our previously created array of questions. This function will be responsible for choosing a unique question each time it is called during gameplay:

Create a randomQuestion function that would pick a random question from our list and return the question name, list of answers, and the correct answer

Add this to your ViewController, and now every time it's called, you'll have a new question randomly pulled from your list of questions.

Developing the newQuestion() method

The next step is to develop the newQuestion() method that fetches a fresh question from our randomly selected pool using our previously created randomQuestion(). This method should also update UI elements such as UILabels displaying current scores and remaining strikes:

Create me a function called newQuestion that will set the question label, update the answer choices, and configure everything.

Writing the checkAnswer() function

Now, let's write the checkAnswer() function that verifies if a user-selected answer is correct or not. This function should also handle updating scores and strikes:

Create me a function called checkAnswer() that is called when a button is clicked, it will check if the answer is equal to the correct answer.

This code should also show you how to map each answer button to checking the correct answer.

Scores and Strikes Function

You can now ask ChatGPT to help you keep track of the score, and penalize the user for getting an answer wrong.

Now edit our existing code to keep track of the user score (increasing 1 point each correct answer) and a strike system that will penalize the user each time they select an incorrect answer. After 3 strikes, just have it print to the screen "lost game"

Wrapping Up

That's literally the basics! You can see how we've fine-tuned our prompts to really ask exactly what we need done.

If you don't have programming experience you might have to just ask ChatGPT how things get done like what is Xcode, what is Swift, how would you make an iPhone app that does xyz.

I had a little bit of knowledge of Xcode before and programmed in another language, but ChatGPT basically held my hand throughout the entire process.

Regardless, this is only the start of some really cool things to come. If you were to spend another hour polishing this up and customizing it to your liking, you'd have an app that's ready for testing!

We're getting to the point where lack of technological skill won't hold you back. Learning is getting more and more accessible, and thanks to ChatGPT, you now have an even deeper level of skill as you have a free tutor by your side 24/7.

Have you used ChatGPT for coding before? Have you made any apps with it? How did it go? Drop a comment below to let us know how it went!

Want to Learn Even More?

If you enjoyed this article, subscribe to our free newsletter where we share tips & tricks on how to use tech & AI to grow and optimize your business, career, and life.


Written by Justin Gluska

Justin is the founder of Gold Penguin, a business technology blog that helps people start, grow, and scale their business using AI. The world is changing and he believes it's best to make use of the new technology that is starting to change the world. If it can help you make more money or save you time, he'll write about it!

Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments