How to handle internet connection reachability in Swift

Neo
We’ve moved to freeCodeCamp.org/news
9 min readNov 30, 2018

--

More often than not, mobile applications need an active internet connection to function properly. It is normal, however, for the internet connection to be lost. In cases like these, it is up to the developer to come up with ways to make the experience bearable, or in the least, notify the user.

In this article, we are going to see how we can detect internet connection issues in Swift, and some ways we can handle it.

Here is the sample application we will be building and how it handles different internet connectivity scenarios:

Requirements

For you to be able to follow along in this article, you will need the following requirements:

  • Xcode installed on your machine.
  • Knowledge of the Swift programming language.
  • Cocoapods installed on your machine.

When you have the above requirements, let’s dive in.

Setting up our workspace

Before we begin, we will create a playground. This is where we will write all our use cases and handle them.

--

--