Posts

Showing posts with the label Class

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...

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: ...

Treehouse Intermediate Course - Part 15 (Delegation 2)

So there just wasn't a chance yesterday to code! But I'm back today. I was thinking more about creating my own little programme to simulate F1 races and still love that. It could be extended to cricket - a ball by ball approach! But that's something for another time. For now, I'm going to complete this section on delegation; once the race horse example is done, THEN I'm going to play around with the code to see how the F1 sim could work! Cool. Start Time - 08:58 Implementing A Delegate So we need to get any object to adhere to a particular contract, to loosely communicate with race...sounds complex but we're going to find out more! Right so this is the example. This is the delegate - protocol HorseRaceDelegate {          func race( _ race: Race , didStartAt time: Date )     func addLapLeader(forLap lap: Int , atTime time: Date )     func race( _ race: Race , didEndAt time: Date , withWinner winner: Horse ) } De...