Modern Network Reachability in Swift using Structured Concurrency

NetworkReachability

NetworkReachability is a replacement for Apple’s SystemConfiguration Network Reachability APIs. Because these APIs were originally written in C, they are old and cumbersome to use from Swift. NetworkReachability wraps these APIs in Swift and provides a modern interface for the most common use cases.

NetworkReachability supports synchronous reachability queries, as well as constant asynchronous reachability observation via the following mechanisms:

Large parts of the library’s design are inspired by this project by Ashley Mills, which was written before Swift 5.5 and the introduction of structured concurrency.

Installation

NetworkReachability is currently distributed exclusively through the Swift Package Manager.

To add NetworkReachability as a dependency to an existing Swift package, add the following line of code to the dependencies parameter of your Package.swift file:

dependencies: [
    .package(url: "https://github.com/vsanthanam/NetworkReachability.git", .upToNextMajor(from: "1.0.0"))
]

To add NetworkReachability as a dependency to an Xcode Project:

  • Choose FileAdd Packages...
  • Enter package URL https://github.com/vsanthanam/NetworkReachability.git and select your release and of choice.

Other distribution mechanisms like CocoaPods or Carthage may be added in the future.

Usage & Documentation

NetworkReachability’s documentation is built with DocC and included in the repository as a DocC archive. The latest version is hosted on GitHub Pages and is available here.

GitHub

View Github