Mon, Aug 25
Spring-Based Animations Using Damped Harmonics

Erica Sadun wrote a good introduction to adding bounce to UIViews based on spring-based animators in iOS 7:

Although you can always roll your physics-based animations, UIKit now offers one exceedingly handy built-in utility based on damped harmonics.

I’m intrigued, but memory no longer serves me (if it was ever in there at all) on damped harmonics. Google turned up this:

read more »

Sat, Aug 23
What To Do When Things Go Wrong with Git

Kate Hudson is the creator of Git Flight Rules – a guide about what to do when things go wrong when working with Git.

Despite Git’s simplicity on the surface, there is a fair amount of depth to the tool. And with that comes the opportunity to really mess things up.

I like this idea behind this project, it may just save one’s bacon some day.

Fri, Aug 22
Simplifying Swift Asynchronous Dispatch in GCD

Working with dispatch_async is not necessarily difficult, however, the code is typically quite verbose(and lengthy). Tobias Due Munk has published an open source project that provides “syntactic sugar in Swift for asynchronous dispatches.

An example from the github project follows.

A call with dispatch_async that looks like this:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
    println("This is run on the background queue")
    dispatch_async(dispatch_get_main_queue(), 0), {
        println("This is run on the main queue, after the previous block")

becomes this:

Async.background {
    println("This is run on the background queue")
}.main {
    println("This is run on the main queue, after the previous block")

The project includes support for chaining blocks, custom queues, canceling blocks, among others.

Thu, Aug 21
Using Swift for Shell Scripting

I’ve been a command line guy since I started coding (DOS anyone?). Since moving to a Mac my go to scripting language over the years has always been either Bash or Python.

Filip W wrote about using Swift as a general purpose scripting language:

The obvious advantage of such approach is that you now have the same single language to handle iOS programming, OS X app programming and generic system/automation tasks that you might want to perform from the command line.

There are some tweaks you’ll need to make regarding selection of an Xcode version that supports Swift (Xcode 6.x and above). Rob Bazinet has some recommendations about Swift’s Read-Eval-Print-Loop (REPL) by using an alias in your bash profile. Once the production version of Xcode 6 is released, running scripts should be much easier.

Wed, Aug 20
Sliding View Controller Container (Side Menu)

ECSlidingViewController is a nice implementation of a common UI construct wherein a user can swipe either left or right to expose a view underneath. Most commonly this is used to display a menu of options.

Mike Enriquez sums up the design and code implementation as follows:

The philosophy behind ECSlidingViewController is to provide simple defaults while being customizable. It may not work or look the way you want out of the box, but it doesn’t get in the way when customizing it.

A good approach to API development, nothing more frustrating than fighting with a tool that’s intended to help.

Swift Value and Reference Types Explained

Sometimes an assignment results in a new copy of instance data and sometimes the end state is a shared instance. How’s a guy to know which is which?

Apple has an thorough introduction to working with both reference and value types.

And once that is clear, the next obvious question is, where do I use one type over the other? Apple sums this up nicely:

One of the primary reasons to choose value types over reference types is the ability to more easily reason about your code. If you always get a unique, copied instance, you can trust that no other part of your app is changing the data under the covers. This is especially helpful in multi-threaded environments where a different thread could alter your data out from under you. This can create nasty bugs that are extremely hard to debug.

Tue, Aug 19
Working with Strings in Swift

Bumped into a good introduction to working with Swift and strings.

This is interesting:

Strings in Swift are not implemented via a class, they are actually structures. That means they are value types. That in turn means that when you assign them to a new variable, they are copied, so when you change the original String that was copied, the newly stored one is unaffected.

There is also coverage of string concatenation, comparison and interpolation.