|
Hey everyone! Just joined the forum today, and this is my first post. I'm not a professional developer, but I'm not brand new to the concepts either having dabbled in the past in several languages, but I'm new to SwiftUI and to iOS development in general. I'm working on my first app which is a trivia app that will present quizzes of 10 random questions from the pool of items that belong to the selected category. I'm still refining the logic, but my thought was to have a struct for the item (id, question, array of choices, etc.). The pool of items would be an array of struct instances. In addition to this, I envisioned a few [Int] arrays to keep track of things such as:
Given the following setup (which is a simplified version of what I'm really working on), how would you go about creating the arrays mentioned above? Or would you go about it a different way altogether?
|
|
@DaveC skips a few critical lessons in the 100 Days of SwiftUI course and jumps to this:
Welcome to Hacking With Swift@twoStraws has a great program where he lays out basic concepts, builds on that foundation, smashes your assumptions, rebuilds, and introduces SwiftUI concepts along the way. Your question might indicate that you have some programming chops, but aren't sure of an approach using Swift. I'd encourage you to keep your side project but also FOLLOW THE COURSE. Partial AnswerYou don't want my lecture. Probably just the answer? So here's a hint--> Computed Variable. You have an See-> Array Filters In your case, you might consider adding a This is a learning site, so please review this example and see how you can apply it to your problem statement. Please return here and share how your solved your coding question!
Keep Coding! |
|
Not sure where the Questions and Answers are stored or got but look like you making to difficult.
Started with a
now did a
now did a
Added couple of properties
Just added some example data to the
added a couple of computed propeties to make showing in
Add a method to chack answer and to check if number of questions
So this is the
And
I have done this with a app Bus Quizzes which has over 1360 questions (with four answer to each question). PS you could go even better is to make the Array of |
|
Thanks @Obelix and @NigelGee! I appreciate the quick replies. I will spend some time with your suggestions and see what I can do. I know that I have a lot to learn, and having a project is the best way to do it. My only purpose in mentioning that I'm not a complete noob was just so that the suggestions wouldn't be to point me to tutorials about "what is a string?" or "what are funcitons and methods?" So, as long as it's helping learn stuff I don't already know, I'm open to whatever "lectures," examples, or other guidance you have to offer. My first thought was to do have the 10-question quiz be an actual array of TriviaItem structs instead of just the id values. That seems like it would be simpler. Perhaps some additional explanation of the logic would help. The idea is that there are going to be several categories with a pool of 500+ items per category. The user will select a category and take a 10-question quiz. Whichever questions they answer correctly are "flagged" so that they are no longer included in future quizzes and are added to the total score. When a user exits the app, I need to persist the score and which questions were answered correctly, so that when they come back, their score is intact, and the next quiz will not include any questions they already answered. With the need to persist that info, I figured it would be better to persist an array of id values instead of persisting an array of all the structs for the questions that had been completed. Anyway, this is still in its infancy, and I'm at the very beginning of my SwiftUI/iOS development journey, so I appreciate all the coaching, guidance, and even lecturing I can get. Thanks again, and I'll let you know what I come up with. |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.