Posts

Showing posts with the label struct

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

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

Nick Walter Challenges Part 9 (Protocols)

Image
Last one! After this I'm going back to Angela's course to look at Swift in action, alongside various other new things. The point of Nick's courses for me is to make me feel more confident and secure about the syntax of Swift, but to also apply the knowledge to these mini challenges. They have truly made me feel more assured about what I know with Swift. Definitely worth doing! So the last bit from Nick - Protocols! Start Time - 19:24 Protocols So a protocol is a series of rules that need to be adhered to. protocol Age {     var age: Int { get } } Inside the curly brace you can get or get set but not just set! protocol Age {     var age: Int { get set } } class Dog: Age {          var age = 0 } protocol Age {     var age: Int { get set }          func tellMeAboutAge() -> String   } OK I've learned something here. In the...

Classes and Structs - interim Practice!

So I was all ready to move onto the next course but really feel the need to crack the whole initialiser (which is one of the most difficult words to type by the way!) thing first. It makes more sense to have a little more practice with this! So for the first time since going back to Treehouse, I'm veering away from it - albeit briefly... First stop - the Apple Developer Guidance Structures  and  classes  are general-purpose, flexible constructs that become the building blocks of your program’s code. You define properties and methods to add functionality to your structures and classes using the same syntax you use to define constants, variables, and functions. Straight from the text! All of that makes sense. Pasan also referred to them as 'Objects'. Ah hang on, that's an instance of a construct. Again, from the text, here is what both Structures and Classes can do: Define properties to store values Define methods to provide functionality Define subscripts t...