REST API Calls with Alamofire

Last time we looked at the quick & dirty way to get access REST APIs in iOS. For simple cases, like a URL shortener, dataTask(with request: completionHandler:) works just fine. But these days lots of apps have tons of web service calls that are just begging for better handling, like a higher level of abstraction, concise syntax, simpler streaming, pause/resume, progress indicators, …

In Objective-C, this was a job for AFNetworking. In Swift, Alamofire is our option for elegance. Read on →

Pretty UIButtons (in Swift)

There are lots of options for making pretty UIButtons. The simplest way (for the programmer) is to have someone provide an image of the button and text then just set it as the button’s image. But you can also manipulate different parts of the button in code or interface builder. Here’s an example of what can be done in code. Read on →

Are Pants Optional in Swift?

Swift has optional types. Optional types can have a value or no value (like a pointer can have a value or nil). The intention is to replace nil checks everywhere with concise syntax and type safety. An optional type is declared by tossing a ? at the end of the type like so:

var pants:String? = "Pants"

The non-optional equivalent is:

var pants:String = "Pants"

So why is this an improvement over Objective-C? Read on →

Hello Swift

This is my journey to embrace and internalize the world view of Swift. Sadly, integration with Cocoa will probably be under NDA for a while but we can talk about anything that’s in the Swift Programming Language eBook.

For Loop Bugs

One tiny dot will be the source of many, many off-by-one errors:

“Use .. to make a range that omits its upper value, and use … to make a range that includes both values.”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.

Updated Feb 25, 2015: Apple has changed the for loop syntax to this much clearer option that will result in far fewer bugs:

for i in 1...5 {
    //This will execute for 1, 2, 3, 4, 5

for i in 0..<5 {
    //This will execute for 0, 1, 2, 3, 4

Thank FSM.