Modular Architecture in iOS Development

cihannakgul
3 min readAug 17, 2023

--

Modular Architecture in iOS Development

Intro

If we are working on a large and comprehensive project, debug speed, security and separation of responsibilities are important factors. As the project grows, the structures within it become more complex. To avoid this, we use clean architectures such as MVVM, VIPER. So can we make MVVM better? Let’s take a look at what modular architecture is

What is Modular Architecture?

Modular architecture is a approach that allows layers to be used separately from each other in the project. Modular architecture reduces dependencies in the project and allows each layer to be debugged in itself, resulting in a faster and cleaner project. It makes it easier to write Unit Tests and other tests. When using libraries with Cocoapods, it reduces dependencies by specifying which library will be loaded into which module. For example, integrating Alamofire only in the network module is one of the right way

Modular Architecture

Suppose we have a music application. For this app we created three separate modules: Search Module for music search, Network Module for all API operations and Components Module for UI elements. Now we have modules that we can write our codes separately. Let’s take a look at how we did this together

Create a project

  1. First create a project
  2. Open the project folder and open terminal, write “pod init”
  3. On the terminal write “pod install”
  4. Close the project and open from workspace

We use pod for creating workspace. If you don’t wanna use pods, you can create a workspace then create a project inside of it.

Create First Module

After that step we gonna choose workspace. Choose workspace, not the project.

Now we have a module. We have connect it with main project

Connect module with main project

  1. Choose your main project from left bar (MusicApp in our example)
  2. Choose the “General” tab
  3. in the “Frameworks, Libraries, and Embedded Content” section click the add and choose Network.

Thats all! We implemented an example of using a different module within the project. By utilizing this architecture with MVVM, you can work on a clean project structure.

--

--