Posts

Lynda Course - Swift 5 Essential Thinking (Part 6)

Image
Here we go! A quick session now. Not sure how long I've got but gonna do a bit. A couple more chapters of this course, then will review what else from Lynda is worth looking at. At some point I need to decide if the subscription is worth it.  Start Time - 12:57 6. Classes, Structs and Beyond So I looked at the initial couple of videos last time about value vs reference types. Now the focus is specifically on classes. Classes All this is fine - just a recap - class Adventurer {          var name: String     var maxHealth: Int               var specialMove: String ?          init (name: String , maxHP: Int ) {         self . name = name         self . maxHealth = maxHP     }          convenience init (name: String ) {         self . init (name: ...

Lynda Course - Swift 5 Essential Thinking (Part 5)

Image
Right! Back on it after several days away. Still struggling to get into some sort of routine. So I'm glad that I've managed to create a little bit of time now - around 40 minutes. Need to go over some of the last bit on closures before the next section... Start Time - 17:14 Type Aliasing OK, it was this bit to go over! typealias AttackTuple = (name: String , damage: Int , rechargeable: Bool ) var sunStriker: AttackTuple = ( "Bruce" , 4 , true ) I totally get the benefits of type alias. There is no initial value given to the AttackTuple. But the var of sunStriker does.  func levelUpAttack(baseAttack: AttackTuple ) -> AttackTuple {     let increasedAttack: AttackTuple = (baseAttack.name, baseAttack.damage + 10 , true )          return increasedAttack      } levelUpAttack (baseAttack: sunStriker ) An example of how to use the AttackTuple as a type within a function....

Lynda Course - Swift 5 Essential Thinking (Part 4)

Image
Am smashing through this course and enjoying it! Probably because it's mostly recap and consolidation. Anyway, got a bit of time before a brunch today so no time to waste! Start Time - 11:26 5. The Wide World Of Functions So a point here is that a lot of these are already built into Swift. But we can create our own of course! Basic functions All good recap here. Overloading functions Heard of these once before in Pasan's story course. So this is using the same name for multiple functions, as long as their signatures are unique. // Base function func attackEnemy() {     print ( "Attacking enemy..." ) } // Overloaded functions func attackEnemy(damage: Int ) {     print ( "Attacking enemy; \ ( damage ) caused" ) } func attackEnemy(damage: Double , weapon: String ) -> Bool {     if damage > 8.4 {         return true     } else {         return false ...

Lynda Course - Swift 5 Essential Thinking (Part 3)

Image
So, predictably, it's been tough finding time this week. Knew it would happen with work becoming busier! So a quick-ish entry now. Next bit of Swift Essentials! Start Time - 20:46 4. Application Control Flow I love this! Probably my favourite aspect of Swift. Got enough time to complete this chapter as it's a short-ish one. var hp = 91 var maxHP = 100 // If statement (<, >, <=, >=, !=, ==) if hp < maxHP {     print ( "Health is lower than the max health!" ) } else if hp <= 50 {     print ( "Health is running seriously low!" ) } else {     print ( "Health is not registered" ) } Optional Binding   One interesting point is that the temporary value is only available within the if/let statement, not outside of that scope though! Another example with multiple values. Optional chaining -  if let _ = isShopOpen , let searchedItem = blacksmithShop [ "Shield" ], le...