Writing a Swift Network Layer

It’s pretty good

Steven Curtis
14 min readApr 10, 2024
Photo by Omar Flores on Unsplash

I produced a network client that I’m going to use for all of my personal projects going forwards. Instead of using a third-party framework it’s great to understand networking in Swift and create your own (in my opinion). This article explains and documents it. I hope this article helps somebody reading!

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 15.0, and Swift 5.9

Prerequisites:

To install the network manager to which this refers, you will need to know something about Swift Package Manager

Having a handle on generics will also help you out.

Installation

If you wish to use this network manager you can (in Xcode) go to your project and add it as a package dependency. The location is https://github.com/stevencurtis/NetworkClient and the current version is 0.0.11.

The public API

There are two entry points for this network manager — both AnyNetworkManager and NetworkManager are publicly accessible. Not only that — there is a MockNetworkManager that is publicly available for testing.

Network Manager

--

--