Posts

Showing posts with the label designated

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

Chris Ching Course Part 3 (Properties, Initializers, Arrays and Dictionaries)

So this may be the last of these 'consolidation' Chris Ching courses that I'll use. It's been good fun but at the same time I know I am beyond this level of understanding. It's more of a confidence booster really! It's a good job that I like spending time coding and going over this stuff! OK here we go! Start time - 19:13 Properties All fine so far. Chris says that properties are variables inside the class. Well, they are. But they can also be constants! Computed properties - I need to go over this, good! class BlogInfo {     var blogTitle: String     var blogBody: String     var author: String ?     var posts: Int          var fullTitle: String {         if author != nil {             return blogTitle + " by " + author !         } else {             return "Author is unknown" ...

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