Modularity in iOS using Swift Package Manager - Part 1


When I was beginner or some where around 1-2 years of experience I usually developed the app in very monolithic style code base, where I have single repo which contains folders and files depending on kind on design pattern used .

For better clarity please refer to screen shot.

Screenshot 2022-08-02 at 4.59.54 PM.png

Here you can see there are folders which basically separates the appropriate files/classes on the basis of feature or modules.

We can have such monolithic structure if we know we are not scaling soon or may be the development is just started with limited number of team member.

But what will happen if team size starts growing from 3 to 30 developers and people from teams starts asking the question to EM or Leads regarding the responsibilities of a particular code/module/service. Just imagine that chaos.

In that situation we have to move on from Monolithic structure code base to more organised Lego/Modular/MicroServices structure code base. But that can't be done alone EM and leads also need to create Teams/Group of developers who will be taking ownership of specific module.

There is a very common way to segregate the teams which is separation of teams on basis of module also called feature teams and then there is Special task team aka Platform team.

Platform team consist of senior developers who take care of multiple things like code infra , CI/CD stuff and also manages the ambiguity and do check for any redundancy stuff in code base.

Same team is also responsible to keep eye on code base if something can be moved to common packages rather than having the same in feature module.


Lot of talk , lets deep dive into creating the Swift package and move some files into it and use that as package dependency on main app.

I have created a sample package , here is the Github link for the same.

Add SwiftPackage to Main app

Now we have the package , we just need to add that as dependency in our main app. Simply click on + button and enter the GitHub repo link and that's it.

Screenshot 2022-08-08 at 4.13.48 PM.png

Is Job done?

Are we done with Lego stuff , No this is just the beginning , things are not that pretty simple that you just segregate stuff like a charm. Once we started revamping our code base using package manager we have to make certain decision before hand, which I will discuss in detail.

From here we have 2 choice , we can choose either of one or both at the same time . I will explain both.

  1. SPM with intermodule dependencies.
  2. SPM with no cross dependencies.

To be continued ;)