{"id":3071,"date":"2020-09-29T15:46:20","date_gmt":"2020-09-29T15:46:20","guid":{"rendered":"http:\/\/4310.mynmi.net\/?page_id=3071"},"modified":"2026-10-08T16:34:27","modified_gmt":"2026-10-08T16:34:27","slug":"random-trivia-api","status":"publish","type":"page","link":"https:\/\/nmi.cool\/appdev\/random-trivia-api\/","title":{"rendered":"Project 2: Random Trivia API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In this assignment, you&#8217;ll be working with a Random Trivia API: <a href=\"https:\/\/the-trivia-api.com\/v2\/questions\/\">https:\/\/the-trivia-api.com\/v2\/questions\/<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Refresh your browser and you should see a new set of &#8216;trivia&#8217; objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Your Goal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Draw upon everything you learned in the previous <strong><a href=\"https:\/\/nmi.cool\/appdev\/lists-with-swiftui\/\">Lists with SwiftUI<\/a><\/strong> and<strong> <a href=\"https:\/\/nmi.cool\/appdev\/homework-9-working-with-apis\/\" data-type=\"page\" data-id=\"3820\">Working With APIs<\/a><\/strong> exercises to create:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>a List that displays the questions, that also includes<\/li>\n\n\n\n<li>a NavigationView and NavigationLinks to the questions so that the correct answer appears in a new view when a question is clicked.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Don&#8217;t panic!<\/strong> 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">To begin, <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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! <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ MARK: - QuizItem\nstruct QuizItem: Codable, Identifiable {\n    let category: String\n    let id: String\n    let correctAnswer: String\n    let incorrectAnswers: &#91;String]\n    let question: Question\n    let tags: &#91;String]\n    let type: String\n    let difficulty: String\n    let regions: &#91;String]\n    let isNiche: Bool\n}\n\n\/\/ MARK: - Question\nstruct Question: Codable {\n    let text: String\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You could also put these at the top as in <a href=\"https:\/\/nmi.cool\/appdev\/homework-9-working-with-apis\/\" data-type=\"page\" data-id=\"3820\">Working with APIs<\/a>, the location doesn&#8217;t matter \ud83d\ude42<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hints\/Tips<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Duplicate the&nbsp;<strong>Working With APIs<\/strong>&nbsp;project folder and use the copied project for this assignment.<\/li>\n\n\n\n<li>Especially if you&#8217;re using Xcode 16 or newer, add <code>import Combine<\/code> to the top of your file.<\/li>\n\n\n\n<li>Replace the url that leads to the Pokemon data with<strong> <\/strong><a href=\"https:\/\/the-trivia-api.com\/v2\/questions\/\"><strong>https:\/\/the-trivia-api.com\/v2\/questions\/<\/strong><\/a><\/li>\n\n\n\n<li>Replace the Pokemon and PokemonRequest struct with the two shown above, named QuizItem and Question. You are welcome to copy and paste them. \n<ol start=\"5\" class=\"wp-block-list\">\n<li>Then, replace @Published <strong>var<\/strong> pokemonList: [Pokemon] = []<span class=\"s3\" style=\"font-size: revert\"> with <\/span><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>@Published var quizList: &#91;QuizItem] = &#91;]<\/code><\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>Next, update the do statement by replacing it with&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>do {\n                \/\/ Decode the JSON into your model\n                let decodedResponse = try JSONDecoder().decode(&#91;QuizItem].self, from: data)\n                DispatchQueue.main.async {\n                    self.quizList = decodedResponse\n                }\n            }<\/code><\/pre>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li>In ContentView, you&#8217;ll need to update the List so instead of being List(viewModel.pokemonList) { pokemon <strong>in<\/strong>, it reads<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>List(viewModel.quizList) { QuizItem in<\/code><\/pre>\n\n\n\n<ol start=\"8\" class=\"wp-block-list\">\n<li>Finally, replace the Text with <\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>Text(QuizItem.question.text.isEmpty ? \"No Question Available\" : QuizItem.question.text)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ve added a catch statement to make sure the row is filled even if data is missing<\/p>\n\n\n\n<ol start=\"9\" class=\"wp-block-list\">\n<li>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.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Add Navigation to the Correct Answer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Refer to the Lists with SwiftUI lesson to figure out how to create a <code>NavigationLink<\/code> to the correct answer (<code>correctAnswer<\/code>). You can do this!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What else can I do?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, note that each object comes with a category. You can easily generate a custom feed for a specific category by appending, for example,<br><em>?categories=film_and_tv<\/em> or <em>?categories=history<\/em> to your URL, like this:<br><a href=\"https:\/\/the-trivia-api.com\/v2\/questions\/?categories=history\">https:\/\/the-trivia-api.com\/v2\/questions\/?categories=history<\/a>. You can call more than one category by adding commas like this:<br><a href=\"https:\/\/the-trivia-api.com\/v2\/questions\/?categories=history,geography\">https:\/\/the-trivia-api.com\/v2\/questions\/?categories=history,geography<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Don&#8217;t forget to make this app your own!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Did you&#8230;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>add a title?<\/li>\n\n\n\n<li>add a fun background?<\/li>\n\n\n\n<li>edit the text?<\/li>\n\n\n\n<li>see if there&#8217;s anything else you want to add to make your app better? (ex. make your app refreshable)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Put everything together that you&#8217;ve covered so far and see if you can add some personality to your very own random trivia app. Don&#8217;t be afraid to do some Googling at this point as you play around with your style.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">AI Use + Documentation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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&#8217;ve covered in class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Start With the Core<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Your first priority is completing the core project requirements and demonstrating your understanding of the concepts we&#8217;ve covered in class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have that foundation working, you&#8217;re encouraged to experiment. If there&#8217;s something you want your app to do that goes beyond what we&#8217;ve covered, this is a great opportunity to explore it with tools like ChatGPT, Codex, Claude, Xcode&#8217;s AI features, or another AI development tool.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>AI should help you build on what you know, not replace the process of learning it.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you work with AI, pay attention to the code it generates. Compare it to the concepts we&#8217;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There&#8217;s also a point where AI becomes less helpful. If you&#8217;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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Document AI-Assisted Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If AI meaningfully helps you write, modify, troubleshoot, or understand code, add comments near that code documenting the collaboration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your comments should help explain:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What you were trying to accomplish<\/li>\n\n\n\n<li>Where and how AI helped<\/li>\n\n\n\n<li>What the resulting code is doing<\/li>\n\n\n\n<li>Anything important you learned in the process<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You should be able to explain and understand any code you submit, including code developed with AI assistance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">AI-SUMMARY.md<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Every project should include a file named&nbsp;<strong><code>AI-SUMMARY.md<\/code><\/strong>&nbsp;in your GitHub repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use this file to provide a concise record of your AI use throughout the project. Include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Tools Used:<\/strong>\u00a0Which AI tools did you use?<\/li>\n\n\n\n<li><strong>Goals:<\/strong>\u00a0What did you ask AI to help you accomplish?<\/li>\n\n\n\n<li><strong>Implementation:<\/strong>\u00a0What code, features, or approaches changed as a result?<\/li>\n\n\n\n<li><strong>Learning:<\/strong>\u00a0What did AI help you understand that you didn&#8217;t understand before?<\/li>\n\n\n\n<li><strong>Challenges:<\/strong>\u00a0Did AI provide anything incorrect, confusing, or unsuccessful? How did you respond?<\/li>\n\n\n\n<li><strong>Independence:<\/strong>\u00a0Did you recognize code or concepts we&#8217;ve covered in class? Were there changes you could make yourself without additional AI assistance?<\/li>\n\n\n\n<li><strong>Stretch Work:<\/strong>\u00a0Did AI help you attempt anything beyond the core project requirements?<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You don&#8217;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you didn&#8217;t meaningfully use AI on the project, simply state that in your&nbsp;<code>AI-SUMMARY.md<\/code>&nbsp;file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reflection<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Along with your project, push a <code>reflection.md<\/code> file (150\u2013300 words) reflecting on your process \u2014 what you learned, what was challenging, choices you made, or anything else worth noting about how the project came together. There&#8217;s no fixed set of questions to answer; write in your own words.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your project reflection should also address your use of AI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rather than simply stating whether you used AI, reflect on&nbsp;<strong>how it affected your development process and what you learned from it<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you used AI to attempt something beyond the requirements, tell us about the experiment and whether it worked.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Big Idea<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Core \u2192 Stretch \u2192 Document<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Rubric<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A-Level Work<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Exceptional quality, originality, and\/or insight<\/li>\n\n\n\n<li>Fully meets criteria with no significant errors<\/li>\n\n\n\n<li>Polished, organized, and professional<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>B-Level Work<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Meets all criteria with minor issues<\/li>\n\n\n\n<li>Solid understanding and effort<\/li>\n\n\n\n<li>Good organization and presentation<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C-Level Work<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Meets most criteria; notable gaps<\/li>\n\n\n\n<li>Basic or inconsistent understanding<\/li>\n\n\n\n<li>Organization or clarity needs work<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Below C-Level (Not Passing)<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Disorganized, incomplete, or poor quality<\/li>\n\n\n\n<li>Meets few or no criteria; major errors or omissions<\/li>\n\n\n\n<li>Limited or no understanding and effort<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this assignment, you&#8217;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 &hellip; <a href=\"https:\/\/nmi.cool\/appdev\/random-trivia-api\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Project 2: Random Trivia API<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3071","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages\/3071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/comments?post=3071"}],"version-history":[{"count":29,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages\/3071\/revisions"}],"predecessor-version":[{"id":4386,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages\/3071\/revisions\/4386"}],"wp:attachment":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/media?parent=3071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}