Sign in

iOS developer, Cape Town South Africa. 🏖

SwiftMatters blog saw this article first! Subscribe to my blog to receive my articles as they are published.

Welcome to the Swift Network Layer Series! 👋🏾

In this series, we will be covering how we can code our own declarative protocol-orientated networking layer using our beloved Swift.

Knowing how to communicate with a server and present the response data to a user is a vital skill every iOS developer should have. Over the years Apple has made enhancements to URLSession that make our lives as developers easier which have eradicated the need for third-party dependencies for trivial tasks.

Why? 🤷🏼‍♀️

So why would one write their own network layer when…


A bit late into the new year but let’s get to it…

Photo by Sharosh Rajasekher on Unsplash

Firstly I would like to wish everyone a Happy and Blessed New year! Don’t take it for granted that we made it into 2019. The purpose of this article is to look back at the year 2018 and share some of the successes and some failures in the year.

Retrospection — the action of looking back on or reviewing past events or situations, especially those in one’s own life.

Now, where should we start? I guess right here on Medium…

Writing

2018 was definitely my most active and successful…


I will be starting a series of short posts where I share a small snippet of code. These will be short reads and focus on one main idea.

In the first post of this series, we will look at loading images in our application more efficiently by making use of a cache.

URLCache

The URLCache class implements the caching of responses to URL load requests by mapping NSURLRequest objects to CachedURLResponse objects. It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions.

UrlCache gives us the ability to cache responses…


Navigation is one of, if not, the most important aspect of any application. Choosing how users will navigate through the different screens plays a vital role in your applications success.

With the dawn of the AppStore it was very clear what was the most favoured means of navigation. Hamburger menus, Sliding menus, Sidebars whatever you would like to call them. This form of navigation became synonymous with apps. Personally I find many flaws with Sidebars. But since I am not a UX designer, you can read more design-oriented reviews in this article.

As you might have deduced from the title…


Firstly I would like to express my gratitude to everyone who clapped, commented on my previous post Writing a Network Layer in Swift: Protocol-Oriented Approach 😁👏🏾. After some feedback in the comments and more research, I thought it would be beneficial to address the suggested improvements in this post.

We have two simple modifications that can be made to the project that can improve its functionality.

URLSession

In our previous implementation of URLSession, we made use of URLSession.shared. This code works but it is not optimal. Every time we make a request we instantiate a new session. …


In this guide we’ll look at how to implement a network layer in pure Swift without any third-party libraries. Lets’ jump straight to it! After reading the guide, our code should be:

  • protocol-oriented
  • easy to use
  • easy to implement
  • type safe
  • use enums to configure endPoints.

Below is an example of what we’ll ultimately achieve with our network layer:


Moya is a Swift Network Abstraction Library. It provides us with an abstraction to make network calls without directly communicating with Alamofire. With this tutorial we will learn how to get started with the framework, discover some tips & tricks and learn all basics from code examples.

Why Moya?

Let’s firstly discuss why NOT Moya:

  1. It introduces a dependency to your project. Your project’s success is partially determined by Moya’s stability.
  2. There are way more reasons why you would NOT want to use Moya but they are all derived side effects of point number one. You should always consider the cost of…


Using NSExpression to build a calculator.

The Swift language never seizes to amaze me with all the functionality it provides. I gave myself the task of building a simple calculator as a coding-kata. I had already built a calculator in Java and I remembered the horrendous number of ‘if’ and ‘case’ statement that does all the mathematical logic. So I started out and built my layout as seen in the screen above. I used Snapkit to layout the views. This post won’t cover Snapkit but you can read this as an introduction to Snapkit.

The ‘Math’

So we are going to perform…


Photo by Jakob Owens on Unsplash

As a self-taught iOS developer who learned most of his skills from watching Youtube tutorials and online courses using storyboards became second nature. For sometime I actually did not even know that there was even an alternative to using storyboards in Xcode. Was I wrong ! As my journey in learning Swift progressed I started seeing a number of projects using programmatic constraints in their projects. So I started researching why one would even want to use an auto-layout DSL. I mean the storyboard works and I did not see any flaws in it (that’s what I thought). …


Photo by Ben Cliff on Unsplash

Welcome to part two of the series. Let us finally get something to appear on our screens. If you are at this stage of the tutorial you should have the following:

  • Pods setup
  • API Key from The Movie Database
  • Moya Network Layer Setup (be able to see response in console)
  • Project group structure setup

Top keep this tutorial short what we won’t be covering in this part is connecting our views to our code. So what will we be covering:

  • Wrapping up our network layer
  • Designing our interface in Interface Builder
  • Designing our custom cells

Wrap Up Our Network Layer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store