Sandra L Course Part 6 (lectures 40 to 47)

Two days in a row - first time in a while. Boom! Yesterday was a really useful session, focusing on classes then applying it to a model. It made a few concepts clearer to me, especially the fact that custom types can be passed into parameters/arguments; THEN the object, when created, can be put into the function. Anyway, I said I'd start a new project next. Before I do that, I want to crack on with Sandra's Quiz Project - the next chapter in her course. THAT will be the project I will work on!

Start Time - 13:13

Intro and Stack View

Right so I have opened the project file then Sandra says that we can go from scratch. So I will actually do the same as that's the best way to learn!

Reminder about the new position of the option button. Stack view needed!

Vertical stack view put in. Constraints time.

*Red - missing constraints
*Yellow - conflicting constraints
*Blue - all is OK!



This is just to show that the label and button are like the 'children' of the stack view 'parent'.

So far so good!

Outlets and Actions

Sandra does the same coding of the label and button as Ray. I do NOT like this way - makes much more sense to connect them with the ctrl button. So I've done it the way I prefer.

Connect UI

Right, so Sandra's app has a separate question and answer arrays. Makes sense. I've edited them for F1:

    let questions: [String] = [
    
    "Which driver has won 7 World Championships?",
    "Who won two titles in the row, from 2005 to 2006?",
    "Jean Alesi won his one and only F1 race in which year?"
    
    ]
    
    let answers: [String] = [
    "Michael Schumacher",
    "Fernando Alonso",

   "Jean Alesi"
    ]

Just three so far! Issue Sandra has not the same as mine - all worked as my view controller was the initial view controller.

*Already I have some ideas for making this better. Having the label and button text at the start need to be different...but I can change this later on!

First Quiz Question

OK, so Sandra's way of doing is is putting in the [1] of the question array. I know there is a much better way (having a 'question counter' to add one on, then reveal this each time the question is added).

Anyway, going to see how she does it - yes now she is!

 @IBOutlet weak var questionLabel: UILabel!
    
    @IBAction func showNext(_ sender: UIButton) {
    currentIndex += 1
        
    questionLabel.text! = questions[currentIndex]
        

        
    }

    

So clear issue is that the counter will go past the array value. Control flow needed!

Cool, she has set that as a challenge!

Control Flow

Right here's one way of doing it:

   if currentIndex == questions.count - 1 {
        currentIndex = 0
        
    }

This is a good short term fix. What I would rather have is for an alert to come up with game over, click here to start again etc. Let's see what Sandra does...

Yes exactly the same!

Show Answer

OK I hate to say it but Sandra's app has so many flaws. It relies on the user clicking on the questions and answers in an exact order; there is so much room for error! So I can't really adapt this one. Angela's one was much better. But I'm not abandoning it as she's about to go into modelisation - a class created perhaps...

Modelisation

Well, this was just a bit bizarre. We've suddenly had a 'zip' method thrown in, which is not explained at all and does not really make any sort of sense. 

So, basically a flawed way to make a Quiz app! As the one I want to create is going to be based on Angela's excellent one, I'm going to leave Sandra's ideas for now and focus back on the 'Quizzler' project as a starting point for how I make an F1 quiz app. 

What I will NOT do is just adapt that Quizzler project slightly. No. I'm going to start from fresh, have a go, then use bits from Angela's app to adapt the F1 quiz. 

Finish Time - 14:31 (1 hour 18 minutes total)

Not a TOTAL waste of time. It was useful to use the stack views. I should definitely use moving forward, as it keeps related buttons and labels together. That does make total sense. What doesn't is the nonsensical way of having two separate buttons, which makes the usability of Sandra's app so poor. Seriously. Anyway, like I said, the next step is to work on my second own app. I will start from scratch and then look up Angela's code when necessary. 

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)