Angela Yu Course Part 4 (up to lesson 67)

Finding time for coding is tricky! Yesterday, I was hoping I would a fine a spare half hour on the train - didn't happen. Too crowded! I'm just about finding some time while staying with friends in Basingstoke. I think it's realistic to aim for 20 minutes per day - or a little longer every other day if it's not been possible to code that day. Anyway, I'm really enjoying the Angela Yu course and look forward to finding out more! I think the next few lessons are recapping some of the basics, which I have every need and right to skim over. We'll see though - her explanations are so clear that I'll probably understand some concepts properly for the first time! 

Introduction to Programming Modules

The last two apps have used a lot of fundamental aspects of Swift. Seeing how they work in real life THEN looking at some of the theory makes total sense. I would classify myself as 'Intermediate' at this stage, though this may be generous!

Comments, Print and Debug

Comments - making the code more easily understood. Coming back to the code and knowing what it means! I need to do more comments. Also useful for other coders to use.

UIKit - this is a LIBRARY of code. It makes everything works faster as properties/methods etc. are in-built. Like having a Swiss army knife!

In Playgrounds yo have the output bar to see what is happening, but in normal projects, using the print statement is useful.

Console - this is where things are printed to. Helps us to debug/figure out errors etc.

Data Types, Constants and Variables

Constants/Variables - I know these well! Open/closed lid analogy for these. Containers for values/data.






Strings - concatenation and string interpolation. Again - this is very familiar.

Type inference - not explicitly stating the type. But it's harder to tell what the type is.

Data types - think of it like the shape fitting toy! Fixed data type. Makes sense.

Functions

Take a large number of instructions and then package them together. (This is all recap from before - as is most of the above).



I'm just doing the occasional screenshot and not typing as the information is all familiar. Good god!


Conditionals

func loveCalcualator(yourName: String, theirName: String) -> Int {
    
    let loveScore = Int(arc4random_uniform(101))
    
    return loveScore

}

First of all, a simple function! Then a conditional for returning text to go with it...

func loveCalcualator(yourName: String, theirName: String) -> String {
    
    let loveScore = Int(arc4random_uniform(101))
    
    if loveScore > 80 {
        
       return "Your love score is \(loveScore)! You two are meant to be!"
        
    } else if loveScore > 50 {
        
        return "Your love score is \(loveScore)! It could work!"
        
    } else {
        
        return "Your love score is \(loveScore)! No chance!"
    }
    
    
}

This is a much more interesting use of the function and conditional. It is important the order of the conditional - starting with 80, then going down to 50 as we're using greater than. I could use the && for greater than 50 and less than 80 but not actually needed. 

It's important to remember THE ORDER OF WHICH THE IF STATEMENTS ARE EXECUTED! Good example to go over. 

So that's it for now! It's good to recap this stuff, even if it's not exactly a step forward. Tomorrow evening I plan to finish the rest of this 'programming modules' section, so that I can get back to the Xcode project tasks soon. Peeking ahead a little, the next lesson is a challenge on Playgrounds to create a BMI index calculator. Very tempting to start now but I've been on this for an hour already! Looking forward to it - I'm definitely hooked on Swift! :)


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)