So the plan is to complete this app today - the Quizzler! Like I've said before, this template could easily be adapted. Once it's done, I could use it for F1 questions, GoT...anything! So being able to understand each step, as well as the object oriented programming being clarified, there have been lots of positives. Here we go!
Init the First Question
letfirstQuestion = allQuestions.list[0]
I figured out that this must be the 0 index with that format. Makes sense!
uestionLabel.text = firstQuestion.questionText
Having the class makes a huge difference to the simplicity of the code!
OK, the tag system makes a lot fo sense. Grouping together several buttons and putting in the tags of 1, 2 etc. That would have been useful for the Yahtzee buttons for each option to click. Anyway, that's something to play around with another time.
func checkAnswer() {
let correctAnswer = allQuestions.list[0].answer
if correctAnswer == pickedAnswer {
print("You got it!")
} else {
print("Wrong!")
}
}
How to Progress Through the Question Bank
var questionNumber: Int = 0
So this is a great way of keeping track of something, whether it's the level one is on, the score, or in this case - the question number!
Using += 1 - that is the best way of adding on one! Not ++. Swift removed the ++ for some reason. But never mind!
OK - challenge was to try to figure out what to do when the questions were up - I failed. Tried a few things but they did not work.
Using the Xcode Debug Console
Right, so using the debug console, using the debug area is important here. You can print the question number here, to establish the value. This is 13. OK so I was actually close, just some of the order of things. Encouraging!
How to Implement UIAlertController
Here is how it looks:
Whenever you see the word 'in', you should also use the word 'self'. Not for for-in loops though!
This is linked to CLOSURES. We'll come back to this apparently.
let alert = UIAlertController(title: "Complete!", message: "You have finished all of the questions. Do you want to play again?", preferredStyle: .alert)
This is REALLY useful stuff! It seems of huge importance to have these action buttons in the code - especially for restarting etc. The code is complex so I'm not going to worry about memorising the syntax!
I'm still going for more complex solutions rather than simpler ones - repeating myself. Remember DRY!
High Level Overview
This was all fine.
Track Progress and Score
I haven't typed anything here but lots of logic and problem solving - very rewarding!
UPDATING score in the code so it resets to 0 every time - already done my friend!
Incorporating Objective C code into Swift
OK, so this is to get pop ups to show if they got an answer right or wrong!
We're going to use a code library - we can access this for free basically.
HUD - Head Up Display
So I've copied over the files - no problem. I've included the 'bridging' option too.
I've also created an alteration - randomised messages for the correct/wrong answers! I posted this in the questions as am proud of it!
Well that is all for now. Lots learned but gotta go!
It's Christmas Eve and time to code! To think, a year ago, I was plodding along with some eBook, blindly convincing myself that I was on a steady road to coding greatness. Really, it was from June where I made the decision to start again, humbling as that may seem. It would have been comforting to have completed endless 'beginner' courses but branching out and applying the theory is the key thing, which brings us to this entry. Yes, my second Xcode OWN project! I thought about doing an educational one, as there is certainly a lot of scope and relevance for that, being a teacher and all. However, making a quiz makes sense, for various reasons. First off, I have made this before through Angela's excellent tutorial. No offence to Sandra, but hers is not even close to the elegance and effectiveness of Angela's project. The one thing to take from Sandra is the stack views. Definitely something I will use from now on. This is one of the great things about learning from...
Well, it was inevitable really! In typical fashion, I've managed to go a couple of months without any coding activity. Bad Josh! I half-expected it yet am still disappointed. So, this entry is just to establish that I cannot allow that to happen again. One of the reasons that I decided to organise my coding 'experience' via Blogger was so that the live date and time stamp meant that I couldn't do a catch up session at some point. Essentially, there is nowhere to run or hide! So I've been caught out. Caught out not using or organising my time well enough to get any coding in. But that's going to change. I'm going to do some tomorrow - that is a guarantee! When I do, it will be continuing with the eBook that I was already working steadily through. At some point, I'll do a consolidation of what I know and summary of targets etc. For now, it's just a quick - 'Hey, I'm still alive!' - reminding me that coding is something I want to do and ...
Next day, next lecture! I literally have 25 minutes now so I will see if I get to a natural end point... Extensions Now I know about these already. Extensions are a way of adding more code to different types. E.g. to Int, I could add a function or something that gives more usability. I can also extend custom types e.g. structs and classes. *Udemy course not loading properly. Going to have to delay start time for now. Start Time - 15:39 *I only have around 15 minutes for now so will have to continue the entry for later. OK, so the issue here is that you CANNOT have STORED properties in extensions. Right, so in this case, the description property is computed. So this is a cool example of using a new property (computed!) for Int. Squared! So that is everything we can do with extensions. Most of these are later as you can see. So far, that's good. I had to race through some of the using init...
Comments
Post a Comment