|
|
|
I'm working on it now but am struggling with creating a Question struct with a method to build a questions and answers array of all possible questions and answers. Don't know how to create an instance of the Question struct and make the questions and answers array available in the ContentView. There is a post on the forum with the same title as yours to which I posted my issues but haven't gotten any replies so kind of stuck. I did go ahead and build some logic to create a quiz array from the questions and answers array based on user input for times table to practice and number of desired questions. I build that in a Playground with a manually built questions and answers array and it now appears to work base on user inputs. That code is below. There is without a doubt a more elegant solution to creating the quiz array but without any additional hints I went ahead with my logic. I kind of brute forced the creation of the quiz array but it works. Would be interested in yours and any other more elegant solutions. If you could provide some insight into building a Question struct that creates a questions and answers array that I can make available in ContentView that would be much appreciated. :-) Here is the Questions struct I build to create a questions and answers array. Just don't know how to make the array available in ContentView.
Here is my code to create a quiz array from a questions and answers array. I build it in a Playground so does not include a ContentView.
|
|
|
|
Hausmark says:
Now might be a good time to Step Away From The Code. Have a converstation with yourself and ask, "Haus? What, exactly, is a question here?" Your answer above is a struct (named Question) that contains what exactly? It contains an array of Parts of a Maths Quiz QuestionNow, dig in. Ask yourself what are the parts that make up a maths multiplication quiz question? And once you have the parts, what would you likely do with those parts? You might noodle through these questions ending with this short list:
Using these user requirements, you might then create a simple
This is a concept known as "Keep It Super Simple", aka the KISS principle. A single problem only knows about its two operands, its answer, and knows how to generate a label. It does nothing else! Now, when ever you've created a maths problem, you never need to hand craft the label, or calculate the answer. You've encapsulated these responsibilities to the Nota bene: |
|
Now that you've defined a proper maths problem, how can you use this object to create a quiz? Again, step away from the code. WIth paper and pencil, write down a simple quiz, then identify the parts of the quiz. You'll use these parts in your Parts of a Quiz StructYour notes and requirements may be different. But I came up with these:
So define a Quiz struct and code in these requirements. I hope you are using
|
|
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.