|
I'm struggling with a portion of the Multiplication game and think I may have a basic misunderstanding of what is going on. My approach has been to create a struct for a Question (multiplicands and answers), then an array of random questions corresponding to the parameters. For each round, then, I would pop the last Question off the array and compare the user input to the answer and update score. Seemed straightforward. Problem I'm having is that whenever I try to initialize the first question as var q : Question = questions.popLast() in some form, I get into a spot where Swift tells me that I'm trying to use a property initializer before self is available. I've tried changing it to be in a function, in a closure, using lazy or even an init function all to no avail. Help!
|
|
You're almost there.
Note: Instead of assigning a default And another note: The way you are generating the |
|
Thanks so much for your help, that did it! Your point about dupe questions is a good one. My thought was to create the entire pool of possible questions (iteration) and then randomly pick n from the pool. On my to-do list! |
|
SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!
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.