About a year ago, while moving Foto Flipper from Objective-C to Swift, I found there was no native Swift replacement for Apple's Reachability code.

For those not aware, this is an Objective-C wrapper, supplied by Apple, on the SystemConfiguration framework C functions, allowing the app to see the current network connectivity state (wifi, cellular or none) and be notified of any changes. This lets the app handle poor or no connectivity gracefully, rather than failing on web service calls with an obscure error message.

Apple's code has been around since 2008, using NSNotifictions to signal connectivity state changes. Since 2011, however, the go-to code to do this has been Tony Million's open-source Reachability, which added block callbacks, making handling updates much simpler.

Taking Tony's code as my inspiration, I wrote version 1 of Reachability.swift - although it soon became apparent that Swift 1.0 wasn't quite up to the task. Versions of Swift prior to 2.0 didn't allow closures to be converted to C function-pointers, meaning a SCNetworkReachabilityCallBack couldn't be set. The work around was to fire a timer every half second an check the reachability status then.

Finally, with Swift 2.0 and closure to C function-pointer support, Reachability.swift was completed, and now is a Cocoapod and as of today, supports Carthage.

Reachability.swift is on GitHub: