Modular Architecture in Xcode iOS

Muhammad Awais
4 min readMar 30, 2023
Photo by Mario Mesaglio on Unsplash

Problem:

In a small project with only a dozen or so modules, interdependencies between modules aren’t a huge problem, but as your app grows to contain hundreds of modules, the effect all this recompilation has on build times becomes increasingly noticeable and unsustainable. Highly coupled modules if multiple teams working on same app

Solution:

Divide and Concur is solution of many problems and applied here too.
How! You got a requirement to integrate a new feature i.e In-App-Wallet instead of making subfolders in the same target, create a brand new Framework (Looks difficult but easy).
Import that Framework whatever place you need and call their functions and implement delegates if you have created.

Benefits:

  • Increase build time in big scale projects.
  • Different teams can work independently.
  • Change Target in Xcode to that of the particular module you’re working on means that it alone gets built without building whole project.
  • Create module as a framework and use in any other app (plug and play)
  • Every framework can have their own design architecture i.e VIPER, MVVM or MVC.
  • Easy to scalable, add as many as new modules/features.

How?

Here you have brand new app to which you want to add new feature.

New project with pods installed

Create new project and select Framwork:

Name the project and select bundle id

Select your main app here

New module created and looks like this:

Now you have to create new Target by pressing + button in TARGETS. It will create new target by which you can run this module seperately.

Select App:

Add module name by concatenating “Preview” which means you can run this scheme stand alone:

Now target has been created.

What Next?

Because you are creating new framework. You have to delete Mac from destination:

If you have multiple schemas with different names like “Live” “Stage” then you have to rename their too:

If you have more then one sub modules and you want to use them inside your new module, you have to add them in Link Binary:

As you can see in “WalletModulePreview” there is a storyboard, viewcontroller and Assets. This is the app which you can run stand alone.

Last Step:

Use shared Pods:

Name your target and add pods here and run Pod Install.

WalletModule is the framework where you have to add all your files and implementation

Note: Make sure to select Target Membership for both files:

Last Step

You need to call newly created framework inside your main app. Just have to add library link path like this:

Import this framework anywhere in your main app and you can use tham.

That’s all.

--

--

Muhammad Awais

I am IOS Developer with 6+ years of experience in using IOS SDK, Objective C, Swift, Cocoa Touch framework and XCode. I work hard to write good, reliable code