Posts

Showing posts with the label closure expression

Treehouse Intermediate Course - Part 11 (Closures 2)

Image
So, as expected, I had to miss two days. But I'm back! I have a bit of time this evening to carry on with closures - certainly, completing the first part of the Treehouse track. So far, it's all been fine and I haven't found any issues. OK, let's go! Start Time - 18:56 func gameCounter() -> IntegerFunction {          var localCounter = 0          func increment( _ i: Int ) {         print ( "Integer passed in: \ ( i )" )     }          return increment } So just a reminder of scope. The localCounter variable is local as it is inside the body of the method; it can't be used outside that function.  *Paused at 19:03 (not able to concentrate - need to come back to this to take it in properly.) *Continued at 20:11 The increment function now has localCounter += inside it. It can use the localCounter var as it is defi...

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