Posts

Showing posts with the label required

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

Treehouse Intermediate Course Part 4 (Initialization)

Image
I deliberately had a break yesterday - I figure it's health to 'let the information settle' and also not set an unrealistic precedent of coding every day! If we're aiming for the three hours per week, then that can start from NOW and we'll assume I hit that target last week! So continuing with initialization. Let's go! Designated and Convenience Initializers So Pasan makes the point that in value types (e.g. structs/enums) initialzation is only needed when doing a custom one. For reference, it is necessary and is important to refer to the super/base class... Classes have two types of initializers. Designated - central point of init, classes must have AT LEAST one of these, they're responsible for initializing stored properties, and responsible for calling the super init. So so far we have been using designated ones. Classes typically have one - they have to have at least one. We'd get an error without using an init method. class Vehicle { ...