Posts

Showing posts with the label up casting

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 4 (lesson 7)

Image
Back with Bob! Error Handling makes a lot more sense to me now. In my mind, you have if/let, guard/let and the ?? options to see if optionals have a value. Also, you can build in specific error handling options with a enum with messages, which follow the Error protocol. Then the do/try/catch block of code is used to test for errors. Error handling can also be built in to functions, to test for an error and also in classes within the initialisation. Like I said, I know a lot more this time round when I did EH with Treehouse! Right let's go! Start time - 12:20 Type Casting It's useful to start with the 'problem' Bob describes, to give this some sort of focus - So the keyword 'as' I've used before, but I can't remember how! Here's an example with 'as' let label = UILabel () as UIView class Human {          func introduce() {         print ( "I am a human" )     } } class Korean: Human ...