Posts

Showing posts with the label convenience

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

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 10 (lectures 16 to 18)

Such a busy week - first chance I've had to code for a while! Last time, it was REALLY useful to consolidate and go through what I had done previously. Now I am ready for the next chapter: Object Oriented Programming! Let's go! Start Time - 16:57 Convenience Init I know that these are used with classes but can't remember the purpose of the 'convenience' init. Is this just an alternative way of initializing? Not sure! So this is to do with initializing quickly. Lazy keyword? class Human {     var name: String     init (name: String ) {         self . name = name     } } let larry = Human (name: "Larry" ) let jeff = Human () In the above, an error comes up as I have not initialized the jeff object.  Here we go! class Human {     var name: String     init (name: String ) {         self . name = name     }    ...

Nick Walter Challenges Part 8 (Extensions)

Image
Cracking on with Nick's course. I'll be starting with extensions - I can't actually remember what these are! So it will be interesting to see. Start Time - 18:00 Extensions class Dog {     var name = ""     var age = 0 } extension Dog {     var birthYear : Int {         return 2018 - age     } } let theDog = Dog () theDog . age = 8 theDog . birthYear That was it! It's come back to me. An extension is a way of adding to a previous class etc. But why bother with this - couldn't I just put the extension in the original class? extension String {     var EXTREME: String {         return self . uppercased ()     } } var name = "Josh" name . EXTREME Ahhhh OK I can extend other types too - like strings! Nice! extension String {     var EXTREME: String {         ret...