Posts

Showing posts with the label lazy

Bob Lee Course Part 17 (Lecture 29)

Image
Unusual time to be doing an entry? Yes, absolutely! I have laryngitis - so I basically have to be off work, both yesterday and today.  A blessing? Probably! Well, the upshot is that I get to do some coding today, a rare treat. It's been difficult finding any time recently due to going to the F1 in Abu Dhabi, work and laryngitis! So, let's pick that up with Bob's course. Last time it was an introduction to closures. It was hard! From what I remember, closures are another way of writing functions. They can actually be simpler - VERY simple if you use the $ syntax for accessing the values. Still, the whole thing was tricky. Let's continue with the aim of finishing Chapter 3 today! Start Time - 11:27 Lazy Init with Closures My take - I know a bit about lazy already. I know that this means the value does not take up any space until it is used. So it is good for memory management. So that is the code for creating a UIButton. Bob's point here is that to create ...

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