Posts

Showing posts with the label didSet

Stephen DeStefano Swift 5 Course - Part 4 (Lectures 12 to 16)

Image
Not going to go into rambling detail about how it's been a long time etc. End of term, start of holiday is always mental! I have missed my regular coding so am going to get some in today, then there will be more on Monday! I was working through Stephen's course, which was becoming pretty technical and challenging. Let's go! Start Time - 07:17 Stored Properties So these store constant/variable data. A key point here. Structs are value types - if you have a constant stored property, you cannot change the value. You can for classes as they are reference types. All that was pretty easy to be honest. Lazy Properties So I'm just trying to figure out the purpose of these! Stephen is quite rambling. OK so when the property is actually initialised, that's when the lazy stored property is accessed. It's about saving memory. So not created until it has actually been used. If it's computationally expensive - if it will end up slowing things down! Right...

Bob Lee Course Part 15 (Consolidation of Chapter 2 - lectures 16 to 25)

So, a great chance to make sense of all of the concepts in Chapter 2. I will then crack on with Chapter 3 tomorrow! Chapter 2 was all about Object Oriented Swift. A lot of the terminology was familiar but I do feel on the most part (other than singleton stuff...) that my understanding improved with all of this. So let's go over it now! Start Time - 12:03 Convenience Init My Take - this is very simply another way to initialize an object. It's called convenience because the block of code for that init method has it all going on, then the initialisation process is very simple, or convenient. It could be as simple as using () after the class name. Yep, got it! Here's my example from before: class  Human {      var  name:  String      init (name:  String ) {          self . name  = name     }           convenience   init () {     ...

Bob Lee Course Part 11 (lectures 19 to 20)

Image
Schoo inspection is over! This thankfully means that I will have more time to code in the coming weeks. Last time I focused on computed properties including get/set. Now not all of that worked before. Never mind. Anyway, we're starting now with 'property observers' - getSet and willSet. Let's go! Property Observers Start Time - 15:04 So that is the difference between willSet and didSet. Interesting. var myGrade: Int = 80 {     willSet {         print ( "Hey something happened!" )     }     didSet {         print ( "Hey something else happened!" )     } } myGrade = 100 Simple enough but once again my playground seems to be using the same error message of the code not compiling.... Paused at 15:09... Right I am doing the update on Xcode - we will see if that helps! It could be the mac needs an update too...Anyway, I'm going to crack on just by looking at...

Nick Walter Challenges (Part 5)

Image
Yes I managed to find time for one more session! So here we go - now going on to properties. The next several will be all linked to class aspects, so I'm actually going to go through them before the challenges. Always worth building my knowledge up on these as I need to! Start Time - 20:34 Computed Properties So from what I can remember about these, the property is not stored but requires some sort of computation. In the example below, I have two stored properties: class Dog {     var name = ""     var age = 0 } So this is a computed property - it requires the use of the stored property of age and creates a  temporary one of current year. Makes total sense.  var birthYear: Int {         let currentYear = 2018         return currentYear - age     } This looks like a function - using return and all. I could actually use a function but a computed property is bet...