Patterns and Layers for iOS applications

Julius Nyule
2 min readApr 25, 2021

--

After building a few iOS apps of different complexities, as an iOS developer, you start to notice that there are distinct layers of responsibilities in every app’s codebase. You will begin to notice that all the apps you build will be doing one or more of the following: HTTP networking, JSON parsing, data serialization, storing data to disk, UI composition, location GPS work, and other tasks.

These tasks can be grouped into the following layers of responsibilities:

  1. Storage Layer

The main responsibility of this layer is to store data for your app. An example of what goes into this layer could be the following: in-memory arrays & dictionaries or sets, KeyChain, UserDefaults, Disk File storage, Core Data, Realm, and SQLite

2. UI Layer.

This layer is responsible for drawing things on the screen. An example of what goes into this layer could be the following View Controllers(which is supposed to control the view), View Models (which helps to decouple views from other layers of responsibility). One main thing that you will find in this layer is the UIView subclasses (which include Autolayout, Table Views, Collection Views, Buttons and etc).

3. Business Logic Layer

This layer is responsible for handling objects that are responsible for your app’s business logic. It makes your application useful as it helps in keeping the service, storage, UI, and other layers decoupled from each other and tell them what to do to achieve the results of the user of the app. An example of what goes into this layer is Coordinators (which use HTTP service objects with storages to provide smooth receiving of data from the backend APIs as well as persisting it to storage options such as Core Data) and Manager object (which could take care of token encryption and saving it to the keyChain storage).

4. Service Layer

Is responsible for handling network-related tasks and external communication. Think of it like the code that knows how to work with external interfaces such as HTTP client (which helps your app to do networking and connect with the backend JSON API ) or BLE client (aka Bluetooth Low Energy a client wrapper that helps your app to send and receive data from external Bluetooth devices).

The overall structure of layers would look like the following diagram.

iOS App structure overview inspired by SOLID principles.
iOS App structure overview inspired by the SOLID principles.

Reference

The iOS Interview Guide by Alex Bush

--

--