*CONSOLIDATION ENTRY* Lynda Course

OK! So before beginning the pathway on raywenderlich.com - which looks great by the way - I want to consolidate everything from Lynda, so I can help pinpoint what I need more practise with. Before that, I just want to repost something I did several weeks ago - 

Step 1(June 2018-December 2018) - learn the basics syntax and principles of coding with Swift.

Step 2 (January 2019 - June 2019) - learn more intermediate level coding and create several of my own projects.

Step 3 (July 2019 to December 2019) - build on the intermediate concepts, learn some more advanced elements of Swift and create more complex mini apps/projects.

Step 4 (January 2020 to June 2020) - learn the highest order/most complex aspects of Swift. Use RayWenderlich newsletter, London App Brewery - any way of keeping up to date with knowledge and application of the most recent Swift. Make even more complex projects, which are near to 'app ready'.

Step 5 (approx July 2020 to December 2020) - Focus on building and developing apps. Tighten up on knowledge and go over any areas unsure about. Contribute to any online forums/discussions. Network with other Swift users.

Step 6 (approx January 2021 to June 2021) - Start looking at ways to make actual money from coding! Actually start selling apps on the app store, with the correct marketing/advertising strategies in place. Keep broadening and developing understanding of up-to-date Swift aspects

Step 7 (July 2021?!) - Focus on being an app developer...this will not be a quick, easy process and could take months. So the date is not really that relevant.

Step 8 - (Who knows?!) - Be a full time app developer. Could be creating courses or my own online content...Or could just be working on projects alongside others. Or a company. Who knows!

It doesn't look too daunting or crazy, although yes this is still very much a pipe dream. Unless I make it happen! At the moment, I am still on step 3, which is fine. I can go over intermediate stuff and get several mini projects done by Christmas. It is exciting to think that I am slowly working my way towards becoming an app developer.

Anyway, back to the consolidation!

Entry 1 (31.8.2019)

Aspects covered: setting up, variables and constants, type safety, type inference, logging and commenting, swift operators, strings, type conversion, bools and logical operators, optionals

Aspects needing more work with: optionals

So I was happy with pretty much all of this. Only thing to look at and go over is optionals. At this stage it was just how to create them (use of ?) and forced unwrapping (use of !). I get the concept, at this stage as this.

So nothing to go over, not yet at least!

Entry 2 (1.9.2019)

We were on a roll here - two consecutive days!

Aspects covered: collections, arrays, array methods, 2d arrays, subscripts, dictionaries, nested dictionaries, sets, tuples

Aspects needing more work with: 2d arrays and nested dictionaries

So the above were new things at the time. I get these but want to look at the syntax again...

var skillTree: [[String]] = [
["Hook""Drive""Cut"], ["Googly""Wrist spin""Chinaman"], ["Catch""Dive""Throw"]
]

So in the example above, we have arrays within an array. The first array has batting shots, the second has spin bowling examples and the third, fielding things. To access these, you need TWO subscripts as it is a 2D array - 2 levels...

var fielderMove = skillTree[2][1]

That would be "dive".

So I could make that 3D....

No let's not!

And as for nested dictionaries...

var gameOfThronesFamilies = [
    "Lannister": ["Tyrion""The Imp""Tywin""The don""Jaime""The Kingslayer" ],
    "Stark": ["Ned""The daddy""Rob""The Young Wolf"]

]

Here we are! In this case, there are two overall groups - lannister and stark. In each of these, there are mini dictionaries. Now accessing these...

var lannisterNickname = gameOfThronesFamilies["Lannister"]?["Jaime"]

Nice! Did that without help. Cool, moving on...

Entry 3 (4.9.2019)

Aspects covered: control flow, optional binding, for-in loops, while loops, switch statements

Aspects needing more work with: optional binding, while loops

I'm generally fine with control flow but will look over bits of this. Optional binding in particular!

if let _ = isShopOpenlet searchedItem = blacksmithShop["Shield"], let quest = questDirectory["Fetch Gemstones"]?["Objective"] {
    print("We have shop open with \(searchedItem) available for \(quest)")
else {
    print("Not all information correct")
}

Wow this was a complex example! This is actually optional CHAINING - having three different values to test if they are there. I can practise with a simpler example first...

if let number = value {
    print("There is a value and it is\(number)")
} else {
    print("There is no value")
}
Yes, made that up and all good. The point is that you BIND the value to a temporary one, and test to see if that can be used. If it can't, then the else statement is printed. 

Moving on to the other optional stuff...

// Test variables
let shopItems = ["Magic wand": 10, "Iron Helm": 5, "Excalibur": 1000]
let currentGold = 16

// Guard statement with for-in loop
for (item, price) in shopItems {
    guard currentGold >= price else {
        print("You can't afford the \(item)")
        continue
    }
}

With this we have a dictionary. Then we have a value of currentGold. Then it is the GUARD statement. Then it runs through the dictionary and picks out anything that does NOT meet the condition. So it is a negative approach. That's why it picks out the >= rather than <=. Think opposite. 

And finally, back to while loops...

var playerHealth = 5

while playerHealth > 0 {
    playerHealth -= 1
    print("Player health is \(playerHealth)")
}

playerHealth = 5

// Repeat-while loop
repeat {
    playerHealth -= 1
    print("Player health is \(playerHealth)")
}
while playerHealth > 0

So you MUST have a value first, not like in for-in, always. The syntax is different to the repeat-while, which will take away one BEFORE anything happens. So it all depends on user aim. OK, not so bad. 

Entry 4 (6.9.2019)

Still maintaining a good effort - only two days later!

Aspects covered: functions, overloaded functions, complex functions, function types, functions as parameters, closures, type alias


Aspects needing more work with: complex functions, closures

I love functions but want to check the complex ones again....

Right some of that was returning multiple values. Let's practise that!

There we go - new example!

func driverInfo(name: String, wins: Int) -> (summary: String, shouldBeChamp: Bool) {
    print("Testing for the driver: \(name) with \(wins) wins to his name...")
    if wins > 10 {
        return("\(name) should be champion!", true)
    } else {
        return("\(name) should not be champion!", false)
    }
}


driverInfo(name: "Schumacher", wins: 12)

Pleased with that!

// Initializing closures
var computeBonusDamage: (Int) -> Int = { (base: Int) -> Int in
    return base * 4
    
}

At this stage, it is just getting the idea of closures. That there is a signature used here. Let's practise this...

var tripleNumber: (Int) -> Int = { (number: Int) -> Int in
    return number * 3
}

var tripleNumberQuick = { $0 * 3 }

tripleNumber(4)


tripleNumberQuick(4)

So with that example above, it is showing the long-winded use of parameter, parameter name, in return etc. then the very easy use of the $0. Anyway. That was pretty much it at this point. 

Entry 5 (10.9.2019)

Aspects covered: type alias


Aspects needing more work with: type alias!

I appreciate type aliases - more recently I've seen the purpose of them - having a complex tuple or signature that you can refer to with a much simpler word.

typealias AttackTuple = (name: String, damage: Int, rechargeable: Bool)

So I can now use the phrase 'AttackTuple' instead of using those parameter names, which means I can also make a var without the parameter names. 

func levelUpAttack(baseAttack: AttackTuple) -> AttackTuple {
    let increasedAttack: AttackTuple = (baseAttack.name, baseAttack.damage + 10true)
    
    return increasedAttack
    
}

There we have AttackTuple as the shorthand so baseAttack is now much simpler.

Also -

typealias ArrayClosure = ([String]) -> Void

func activeMembers(completion: ArrayClosure) {
    completion(partyMembers)
}

In this, the signature of the closure is now used within the function. Inside the function is the array put in there - interesting!

Entry 6 (15.9.2019)

Quite a big gap here - 5 days!

Aspects covered: classes, access modifiers and properties, subclassing, structs, optional chaining


Aspects needing more work with: access modifiers and properties, optional chaining

Right! The access modifiers and properties includes get/set.

OK a better example I have created, using a similar syntax -

struct Rectangle {
    var length: Int
    var width: Int
    
    var area: Int {
        get { return length * width }
    }
}

var rect = Rectangle(length: 4, width: 5)


rect.area

Now let's see if I can make a set...

OK this seems to work...

struct Rectangle {
    var length: Int
    var width: Int
    
    var area: Int {
        get { return length * width }
        set { length = newValue / width; width = newValue / length }
    }

}

Cool! 

Actually, this is better!

struct Rectangle {
    var length: Double
    var width: Double
    
    var area: Double {
        get { return length * width }
        set (newArea) { self.length = newArea / width
            self.width = newArea / length }
    }
}

I think I needed self. 

Entry 7(20.9.2019)

That's another 5 days! Need to fix that for the Ray course...

Anyway, let's see what was needed for this last bit (not needed for entry 8 as this was challenge only)

Aspects covered: enumerations,  raw and associated values, protocols, extensions, throwing errors, error handling


Aspects needing more work with: protocols, throwing errors and error handling

So looking back at protocols first...

OK I've had a look at all of these - I will come back to these along with error handling etc. another time.

Done! I feel that was worth doing and it was great to make sense of several weeks' worth. Tomorrow/next time (Monday latest!) I will be starting Ray's course and extending my learning. 

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)