Posts

Showing posts with the label inheritance

Ray Wenderlich Functions and Types Course - Part 12

Here we are! This will be to conclude Catie's course. It's been useful to go over the content. The issue is that none of it is project-based - I need to see more in context! The MOST useful way of using the info will be in the consolidation entry to follow this. So here we are, the rest on protocols and inheritance! Start Time - 12:56 Protocols and Extensions Extensions - I know about these already. Extending them to protocols... Using protocols you can say 'composition'. If class inheritance isn't quite working then protocols are the way to go! Extensions can't have stored properties or designated inits. At the moment I don't see the advantage of having extensions for a protocol when all of that could just be in one protocol. You can also extend native types e.g. Ints. This is quite advanced! extension Numeric {     var squared : Self { self * self } } An example of putting in member-wise init.  Challenge! Last one fo...

Ray Wenderlich Functions and Types Course - Part 11

Image
OK! This is probably going to be the penultimate part. Maybe last part as I have a good hour so we'll see how far I get. Onwards with protocols! Start Time - 17:00 Initializers This is a pretty lengthly tutorial! Always useful to see this in action. Installing additional Xcode components...will follow along with video without actual coding until that's ready. So the super.init is for the superclass. That needs init. Init phases Phase 1- init all stored properties. From bottom of the hierarchy upwards. Phase 2 - use anything that has the use of self. Two phase init! Then the object is ready to use. If you tried creating an object without declaring the value of the sports array an error would come up. So you an give a default value for that in the class....OR, much better, have another way to init! Use of required rather than override. But required needs to be in the super class. Or the base class. Designated inits. They need to call super.init. So we...

Ray Wenderlich Functions and Types Course - Part 10

Last chapter! The course suddenly got a lot harder with properties and methods so hopefully this will be accessible. Then it will be the consolidation one! Start Time - 17:47 Inheritance For classes, inheritance is something I've used before. class Person {   var firstName : String   var lastName : String      init (firstName: String , lastName: String ) {     self . firstName = firstName     self . lastName = lastName   } } class Student : Person {   var grades : [ Grade ] = []       } let bob = Student (firstName: "Bob" , lastName: "Stevens" ) All of that is fine. The super and sub class etc. Person is a base class and student inherits from that. Person could have as many sub classes as necessary. You can subclass from a subclass. Paused for approx 25 minutes. Polymorphism - a subclass can be treated as its own type or one of its superclasses. This...

Bob Lee Course Part 13 (lectures 21 to 23)

Image
Back to Bob! I have genuinely missed learning new information, having spent a few days doing my mega consolidation project! The will be updated at the end of each 'stage' or mini stage. So my aim now is to complete the rest of this chapter, then I will do a consolidation review of the entire chapter - object oriented Swift. OK, let's get stuck in! Start Time - 17:02 Override Method, Init, Property SO this is what we will be looking at - the super.viewDidLoad bit... I get the idea of the override method. If you have a function with a class, then in the subclass, you want to change how the method works. So you need to use the override keyword. Bob makes the point that if you use the original value of what is returned, then you need to use the super keyword... Xcode doing an update so am screenshotting rather than typing out actual code. All the above is fine - I had forgotten that I still need to use the super bit - even if the value is not...