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.

Mon, Aug 18
Xcode 6 Beta 6 (sans iOS 8 beta 6)

Interesting…Apple released Xcode 6 beta 6 today, however, unlike previous iterations of betas, there is no matching release for iOS 8.

Could it be iOS 8 is good to go, as in, being loaded onto the next iPhone?

Fri, Aug 15
Animate UICollectionView Items As They Appear

UICollectionViews are amazing in their versatility. In an attempt to learn more about animation and collections view, I ran into an interesting post by Aleksandar·Vacić on animating cells.

Referring to his app Try Couch to 5k:

In it, everything is collection views, often nested one inside another. What I wanted to do is sequentially animate each cell as it appears on the screen.

The animation has a nice effect, items appear in the middle of the screen and animate towards the outer edges of the display.