Rss

Archives for : August2017

A Perfectly Lazy Solution

Something nifty with Swift came up the other day, not a big deal, but worth blogging before I forget it again.

Basically it involves the interaction of three things:

  • lazy variables – Variables that are not created until they’re first accessed, typically because their initialization is an expense you’d like to put off (or not perform at all, if the variable is never used).
  • Instantiating variables with closures – When you need to perform multiple statements to set up a variable, you can do something like:
    
    let foo = { ... } ()
    

    which means you’re creating a closure, executing it, and assigning its return value to foo.

  • Delegates. Hoo boy, do we love our delegates…

Continue Reading >>