Posts

Showing posts with the label failable

Stephen DeStefano Swift 5 Course - Part 5 (Lectures 17 to 22)

Image
I'm back! So a good turnaround from the last entry! Yes, I'm going to make time! We're diving into classes and structures, which is always a useful comparison.  Start Time - 15:42 Syntax Ok so a good overview! Syntax I'm fine with so just a recap here. Properties - accessed with dot syntax. Dot syntax - can be used several times e.g. if there is a custom type within the class/struct, then the property of that is used. Sounds complicated but actually very simple! Initialisation -   A good definition! Stored properties cannot be in in an indeterminate state. That means they can't just be up in the air.... So either give default values within the body of the class/struct, or have them created upon the instance being declared. So if a property will always take the same initial value, then it's best to do it as a stored property. Makes more sense then having to init this every time! Value vs Reference Types Ah the age-old debate! In th...

Bob Lee Course Part 15 (Consolidation of Chapter 2 - lectures 16 to 25)

So, a great chance to make sense of all of the concepts in Chapter 2. I will then crack on with Chapter 3 tomorrow! Chapter 2 was all about Object Oriented Swift. A lot of the terminology was familiar but I do feel on the most part (other than singleton stuff...) that my understanding improved with all of this. So let's go over it now! Start Time - 12:03 Convenience Init My Take - this is very simply another way to initialize an object. It's called convenience because the block of code for that init method has it all going on, then the initialisation process is very simple, or convenient. It could be as simple as using () after the class name. Yep, got it! Here's my example from before: class  Human {      var  name:  String      init (name:  String ) {          self . name  = name     }           convenience   init () {     ...

Nick Walter Challenges (Part 6)

Image
Next part - all linked to classes! We have inheritance and initialization - two areas I do need a clearer understanding. Let's go! Start time - 18:09 Inheritance - Subclassing class Animal {     var name = ""     var age = ""          func sayHello() {         print ( "Hello! I am an animal!" )     } } class Mammal: Animal {     var hairColour = ""      } let snake = Animal () let dog = Mammal () dog . hairColour = "brown" dog . hairColour class Monkey: Mammal {     var thumbSize = 0 } let george = Monkey () george . thumbSize george . sayHello () Nothing new here to be honest but nice to recap! Overriding Use of the override keyword if you use the same name of the function from the super class but change its functionality in some way. Easy.  Use of the super. option - thi...