Error Handling - Part 2 (final!)

I wasn't able to do any coding yesterday - flying back from Dubai to UK! Now that I'm back in the home country - for six weeks - I am going to maximise any time I have for coding. Really crack on with all of the courses at my disposal. The plan is by the end of it, to have completed all of the Beginner Treehouse and Udemy courses (unless they're now antiquated), then feel in a position where I can adapt and develop my own ideas - like I did with the simple 'F1 Facts' app.

Speaking of which, I've actually managed to edit this so that there are now two separate buttons which each bring up a separate array - older and newer facts. I actually had three! However, the formatting on my phone was messed up so I left that.

Now I'm having ANOTHER look at it! I reckon that I can make this even more usable and fun. Rather than having older and newer facts, I can group these by 'driver', 'team' and 'circuit'. This will improve the usability basically.

In terms of code, something else I thought of was this - do I really need to do a separate function for each button? It seems long-winded. Perhaps a protocol could be used here? Maybe, maybe! If not, a separate function per button is not the end of the world. Here's how it currently looks:

func randomFactOldSchool() -> String {
    
    let randomNumber = GKRandomSource.sharedRandom().nextInt(upperBound: oldSchoolFacts.count)
    
    return oldSchoolFacts[randomNumber]

    }

func randomFactNew() -> String {
    
    let randomNumber = GKRandomSource.sharedRandom().nextInt(upperBound: newFacts.count)
    
    return newFacts[randomNumber]
    

}

My question is essentially, could I just have one function? Let's try something out...

OK, I've tried that out with a struct and a func and nothing's really working. So I'm going to stick with the 'laborious' code for now...So I'm going to abandon this for now as having an extra button or so really isn't worth it!

Instead of playing around with this for hours, I'm going to crack on with Error Handling. To be honest, I'm not so fussed about this course on ER - it doesn't seem that logical or worthwhile. So I'll continue with it but am so enamoured with the work in the last one it does make it hard to focus. 

Handling Errrors/Cleaning up with Defer

Did not understand a word of this! Had to find the answers to the challenge too. Have accepted that Handling Errors is something I will skim through, gain nothing from, but come back to when I actually need to! Pasan has made a heartening point - that when we're actually building apps, it makes much more sense to comprehend Error Handling! That's good to know!

The quiz was hard - needed several attempts! I've found this with Treehouse before - I've sometimes got stuck with tricky concepts that I see no purpose to. Optionals was another one - not the main concept but the fiddly chaining process. Anyway, I've done it all, so will come back to as and when needed! Next time it will be 'Building a Vending Machine App with Swift'! Now that I'm looking forward to as, again, it will be a chance to put things into context and learn some new skills along the way!


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)