Swift Developer. Living and Xcoding in Brooklyn NY.


Playground: Material Loading Indicator

An Android-inspired, material loading indicator. 

This little project is based on a great tutorial by Matthew Cheok on implementing an Android-inspired, material-style loading indicator, with some minor parameterization and re-factoring. 

Github project posted here


Update: Funny story: this harmless little project led to a very brief moment of Twitter celebrity.

Soon after posting this playground, I tweeted about an initialization technique learned from persuing Erica Sadun's Github, which I used for my initial re-factoring of the stroke start- and end-animations. Namely, you can initialize a Swift constant without having to use intermediate property declarations within the initializing closure. Instead, you can refer to the initialized property using positional references, like so:

let strokeStartAnimation: CAAnimation = {

    $0.beginTime = tailDelay
    $0.fromValue = 0.0
    $0.toValue = 1.0
    $0.duration = tailDuration
    $0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

    return $0
}(CABasicAnimation(keyPath: "strokeStart"))

It's a minor tweak, but makes the declaration a lot more elegant to read (and to write). Apparently, quite a few folks in the iOS community thought so too - enough to get re-tweeted over 100 times! In fact, it caused enough of a stir in the iOS-Twitterverse that within a day, Natasha The Robot had written a whole blog post about it!

Happy that everyone had fun with this tidbit. Makes me wonder how many of these little gems are still yet to be discovered with a deeper understanding of the Swift language and its compiler.