In this assignment, you’ll be working with a Random Trivia API: https://the-trivia-api.com/v2/questions/
Begin by pasting it into your browser and taking a look at the array of JSON objects that appear. Each object includes a question and a correct answer, along with additional information, including an array of incorrect answers.
Refresh your browser and you should see a new set of ‘trivia’ objects.
Your Goal
Draw upon everything you learned in the previous Lists with SwiftUI and Working With APIs exercises to create:
- a List that displays the questions, that also includes
- a NavigationView and NavigationLinks to the questions so that the correct answer appears in a new view when a question is clicked.
Don’t panic! The previous two lessons contain everything that you need to accomplish this assignment, plus there is a helpful trail of breadcrumbs below to help you get through this.
To begin,
copy the two structs shown below and paste them at the bottom of your contentView file. Make sure they are not inside of another struct!
// MARK: - QuizItem
struct QuizItem: Codable, Identifiable {
let category: String
let id: String
let correctAnswer: String
let incorrectAnswers: [String]
let question: Question
let tags: [String]
let type: String
let difficulty: String
let regions: [String]
let isNiche: Bool
}
// MARK: - Question
struct Question: Codable {
let text: String
}
You could also put these at the top as in Working with APIs, the location doesn’t matter 🙂
Hints/Tips
- Duplicate the Working With APIs project folder and use the copied project for this assignment.
- Especially if you’re using Xcode 16 or newer, add
import Combineto the top of your file. - Replace the url that leads to the Pokemon data with https://the-trivia-api.com/v2/questions/
- Replace the Pokemon and PokemonRequest struct with the two shown above, named QuizItem and Question. You are welcome to copy and paste them.
- Then, replace @Published var pokemonList: [Pokemon] = [] with
@Published var quizList: [QuizItem] = []
- Next, update the do statement by replacing it with
do {
// Decode the JSON into your model
let decodedResponse = try JSONDecoder().decode([QuizItem].self, from: data)
DispatchQueue.main.async {
self.quizList = decodedResponse
}
}
- In ContentView, you’ll need to update the List so instead of being List(viewModel.pokemonList) { pokemon in, it reads
List(viewModel.quizList) { QuizItem in
- Finally, replace the Text with
Text(QuizItem.question.text.isEmpty ? "No Question Available" : QuizItem.question.text)
We’ve added a catch statement to make sure the row is filled even if data is missing
- You may need to change a few more variables, but take them one at a time and try to change all instances of pokemon with QuizItem, for example.
Add Navigation to the Correct Answer
Refer to the Lists with SwiftUI lesson to figure out how to create a NavigationLink to the correct answer (correctAnswer). You can do this!
What else can I do?
Look at the feed that you are using. Each object contains, in addition to a question and a correct answer, 3 incorrect answers. Give some thought to how you could turn this whole thing into a multiple-choice exercise with scoring.
Also, note that each object comes with a category. You can easily generate a custom feed for a specific category by appending, for example,
?categories=film_and_tv or ?categories=history to your URL, like this:
https://the-trivia-api.com/v2/questions/?categories=history. You can call more than one category by adding commas like this:
https://the-trivia-api.com/v2/questions/?categories=history,geography
Don’t forget to make this app your own!
Did you…
- add a title?
- add a fun background?
- edit the text?
- see if there’s anything else you want to add to make your app better? (ex. make your app refreshable)
Put everything together that you’ve covered so far and see if you can add some personality to your very own random trivia app. Don’t be afraid to do some Googling at this point as you play around with your style.
AI Use + Documentation
AI tools are allowed and encouraged in this project when they are used to support your learning, troubleshoot problems, or extend your work beyond the concepts we’ve covered in class.
Start With the Core
Your first priority is completing the core project requirements and demonstrating your understanding of the concepts we’ve covered in class.
Once you have that foundation working, you’re encouraged to experiment. If there’s something you want your app to do that goes beyond what we’ve covered, this is a great opportunity to explore it with tools like ChatGPT, Codex, Claude, Xcode’s AI features, or another AI development tool.
AI should help you build on what you know, not replace the process of learning it.
As you work with AI, pay attention to the code it generates. Compare it to the concepts we’ve covered in class. You might be surprised how much of it you already recognize! As your skills develop, you should become increasingly comfortable reading, understanding, and modifying that code yourself.
There’s also a point where AI becomes less helpful. If you’re spending time prompting an agent to make changes you already know how to make, consider whether it would be faster and more valuable to make those changes yourself.
Document AI-Assisted Code
If AI meaningfully helps you write, modify, troubleshoot, or understand code, add comments near that code documenting the collaboration.
Your comments should help explain:
- What you were trying to accomplish
- Where and how AI helped
- What the resulting code is doing
- Anything important you learned in the process
You should be able to explain and understand any code you submit, including code developed with AI assistance.
AI-SUMMARY.md
Every project should include a file named AI-SUMMARY.md in your GitHub repository.
Use this file to provide a concise record of your AI use throughout the project. Include:
- Tools Used: Which AI tools did you use?
- Goals: What did you ask AI to help you accomplish?
- Implementation: What code, features, or approaches changed as a result?
- Learning: What did AI help you understand that you didn’t understand before?
- Challenges: Did AI provide anything incorrect, confusing, or unsuccessful? How did you respond?
- Independence: Did you recognize code or concepts we’ve covered in class? Were there changes you could make yourself without additional AI assistance?
- Stretch Work: Did AI help you attempt anything beyond the core project requirements?
You don’t need to paste every prompt or response into this file. Instead, summarize the important parts of your collaboration. If your AI tool allows you to export or share a conversation and you think that context would be useful, you may include it as additional documentation.
If you didn’t meaningfully use AI on the project, simply state that in your AI-SUMMARY.md file.
Reflection
Along with your project, push a reflection.md file (150–300 words) reflecting on your process — what you learned, what was challenging, choices you made, or anything else worth noting about how the project came together. There’s no fixed set of questions to answer; write in your own words.
Your project reflection should also address your use of AI.
Rather than simply stating whether you used AI, reflect on how it affected your development process and what you learned from it.
Consider what you were able to accomplish independently, where AI helped you move beyond your current skills, and whether working with AI helped you recognize concepts you already understood.
If you used AI to attempt something beyond the requirements, tell us about the experiment and whether it worked.
The Big Idea
Core → Stretch → Document
First, demonstrate the skills the project is designed to assess. Then use the tools available to you to experiment, solve problems, and push your work further. Finally, document that process so you can demonstrate not only what you built, but what you understand.
AI-generated code that you cannot explain is not a substitute for completing the project requirements. Thoughtful, transparent AI use that helps you understand the material, solve a problem, or build something beyond your current skillset is absolutely encouraged.
Rubric
A-Level Work
- Exceptional quality, originality, and/or insight
- Fully meets criteria with no significant errors
- Polished, organized, and professional
B-Level Work
- Meets all criteria with minor issues
- Solid understanding and effort
- Good organization and presentation
C-Level Work
- Meets most criteria; notable gaps
- Basic or inconsistent understanding
- Organization or clarity needs work
Below C-Level (Not Passing)
- Disorganized, incomplete, or poor quality
- Meets few or no criteria; major errors or omissions
- Limited or no understanding and effort