Apr 25, 2016

Updating an Objective-C library for Swift

Recently I updated an Objective-C library for improved Swift interoperability. The Objective-C library hadn’t been touched for a while to the extent that it still used manually memory management rather than ARC. Converting a pre-ARC library added additional challenges.

All the changes made are contained in this pull request. I also added a Travis CI build for the library.

More »

Apr 20, 2016

Avoiding Swift's [Any] by using functional patterns

In my previous post: “Unexpected behaviour with Swift’s [Any]”, I declared a nested array of integers as:

let a : [Any] = [1,2,[3],[4,[5,6]],[[7]], 8]

Using Any feels like a code smell; by using Any I’m effectively saying, “ignore all the type-checking the compiler performs, instead I’ll rely on my own knowledge of the types”. Experience shows I am not as knowledgable as the compiler, especially after some time has elapsed and I’m trying to add a new feature…

More »

Apr 19, 2016

Unexpected behaviour with Swift's [Any]

Any idea why the following code is generating a runtime exception?:

Adding an explicit type declaration solves the problem:

But why?

More »

Mar 7, 2016

Type erasure with AnyError

NADocumentPicker returns a Future<T, E: ErrorType> with the type:

Future<NSURL, AnyError>

What is AnyError in the above code? AnyError provides a unified concrete error type for a Future . A unified error type is necessary when composing futures with flatMap so, if one of the futures fails, the error can be propagated through the compositional chain.

More »

Mar 7, 2016

NADocumentPicker - Swift document picker UI

I’ve released a Cocoapod that encapsulates UIKit document picker UI; allowing the user to select iCloud documents (and Google Drive, One Drive, etc), with a simple Future based API.

More »