TheAwesomeApp: Develop multi module iOS app with ease

Zaid Pathan
LushBinary
Published in
6 min readMar 25, 2019

Managing large apps in large team is difficult. Compile time, merge conflicts, merge time, and many more things can be time consuming and difficult. This is how we made it easy.

Advantages of given approach

  • Using following approach you will be able to manage multi-module apps with ease
  • This approach will reduce compile time, merge conflicts, merge time of your large scale apps

Prerequisite

Xcode 10.1+, Carthage 0.32.0+, Basic knowledge of iOS

Project Requirements

Recently we have worked on one of the most challenging app which was having multiple modules. Hence managing that app was crucial.

There are 4 the major modules in the app:

  1. Chat — Whatsapp like realtime chat feature
  2. Play — Spotify like music feature
  3. Pay — PayTM like payment feature
  4. Shop — Flipkart like shopping feature

All in single app 📱.

This is how we implemented this large scale app with utmost ease.

Step: 1 — Projects creation

Our approach will be creating 5 separate projects on GitHub and on Xcode both. 1 would be main project called TheAwesomeApp in which we will merge all other 4 module’s projects.

  1. TheAwesomeApp 📱— Name of the main project that will be main centralised app in which we will merge other 4 modules.
  2. Chat 💬Name of chat module project
  3. Play ▶️— Name of play module project
  4. Pay 💰— Name of pay module project
  5. Shop 🛒 — Name of shop module project
GitHub: Create repository for all 5 projects
Xcode: Create Single View App for All 5 Projects
Xcode: Create Single View App for All 5 Projects

Once all 5 projects are created on GitHub as well as using Xcode, we are ready to start some basic apps setup for demonstration.

Step: 2— TheAwesomeApp setup

In TheAwesomeApp, We will add one UITabBarController, and we will fetch view controllers for each tabs from other 4 modules.

Open Main.storyboard, Delete everything inside it and add one UITabBarController object to it.

Then delete all other view controllers attached with it. Also mark it as Initial View Controller. The end result should look like as below.

TheAwesomeApp: Setup Main.storyboard

Now if you will run the app, nothing will be shown except a black view with blank tabbar like this:

TheAwesomeApp: Blank tabbar

Now we will add view controllers to this tabbar, not from same project but from other 4 modules.

Step 3: — Chat module setup

Important: We will use an amazing feature of Carthage here.

Carthage let us create a shared framework in our reusable modules(Ex: Chat module) and then integrate those modules into our main app, TheAwesomeApp.

Open Chat module’s project and add new target to it.

File > New > Target > Cocoa Touch Framework

Chat: Add Cocoa Touch Framework Target
Chat: Add Cocoa Touch Framework Target
Chat: Add ChatModule as Cocoa Touch Framework Target
ChatModule: Make scheme shared

To make this framework shared, make sure the schemes are clicked as shared as follows. (Unselect then reselect — Sometimes we get Xcode bug.)

ChatModule: Make scheme shared by unselect/reselect shared ticks

Add storyboard and ChatViewController to ChatModule. This ChatViewController will be used in TheAwesomeApp.

ChatModule: Add ChatModule.storyboard
ChatModule: Add ChatModule.storyboard
ChatModule: Add ChatViewController
ChatModule: Add ChatViewController

Now we will design ChatViewController in ChatModule.storyboard and give class name and identifier to it as well.

Open ChatModule.storyboard and add a ViewController to it.

Add ViewController to ChatModule.storyboard

Don’t forget to give it Class as well as Identifier names.

Important: Push the Chat project to the GitHub

Now, we are ready to use this ChatViewController into TheAwesomeApp.

First we will add ChatModule to TheAwesomeApp. Once it will work as expected, we will follow the same process for other 3 modules.

Step: 4 — Adding Chat module to TheAwesomeApp

Open TheAwesomeApp project in terminal and fire following command:

Terminal: Create and open Cartfile
TheAwesomeApp: Cartfile added

This Cartfile is responsible for fetching ChatModule to TheAwesomeApp.

In this Cartfile you have to write path of your Chat project’s GitHub repository as follows:

TheAwesomeApp: Cartfile

Note: Please make sure you replace your user name with mine. ZaidPathan is my user name on GitHub.

Run following command in terminal to fetch ChatModule to TheAwesomeApp.

Terminal: Fetch ChatModule through carthage

The above command will fetch whatever shared framework is defined in list of repositories in Cartfile, in our case it’s ChatModule from ZaidPathan/Chat repository.

If everything is setup properly, you will see ChatModule will be fetched.

Terminal: Fetch ChatModule using Carthage

You have now ChatModule is ready to plug-&-play, let’s use that into TheAwesomeApp.

Step 5: — Using ChatModule into TheAwesomeApp

Open TheAwesomeApp folder and go to Carthage>Build>iOS folder. There you will see ChatModule.framework, drag-&-drop that into your TheAwesomeApp project. Make sure Add to targets is ticked.

TheAwesomeApp: Drag-&-Drop ChatModule.framework

Add ChatModule to Embedded Binaries of TheAwesomeApp.

TheAwesomeApp: Add ChatModule to Embedded Binaries of TheAwesomeApp.

Now open Main.storyboard in TheAwesomeApp and add Storyboard Reference to it.

Click on Storyboard Reference and set following details to it:

Storyboard: ChatModule

Reference ID: ChatViewController

Bundle: com.ZaidPathan.ChatModule (Bundle Identifier of ChatModule framework, this will be different for you)

TheAwesomeApp-Main.storyboard: Add Reference Storyboard and details

Ctrl+Drag from UITabBarController to Reference Storyboard and set it as view controllers.

TheAwesomeApp-Main.storyboard: Set Reference Storyboard as view controller of UITabBarController

Press ⌘+R, If everything is implemented properly you will see ChatModule’s ChatViewController as first view controller of UITabBarController.

TheAwesomeApp: ChatModule’s ChatViewController. 😍

😍 Happy happy 😍

We have successfully added ChatModule to TheAwesomeApp.

Step: 6 — Use all other 3 modules into TheAwesomeApp

In order to do this, Follow Step-3 to Step-5 for all 3 other modules as well, and final Cartfile will look like this.

TheAwesomeApp: Final Cartfile

Run following command again to fetch all 4 modules to TheAwesomeApp.

Terminal: Fetch all modules through Carthage

And the final result should look like this:

TheAwesomeApp: All frameworks are added
TheAwesomeApp: Final Main.storyboard
TheAwesomeApp: Final Embedded Binaries

Press ⌘+R, If everything is implemented properly you will see UITabBarController with all 4 modules added into it. You won’t be able to see different tabs as because we haven’t named them, but still you will be able click on each of them.

To add title to each tabs, add UITabBarItem to each ViewControllers in their own storyboards and add relevant titles to them.

Press ⌘+R, and see the final result:

TheAwesomeApp: Final result with all 4 modules

💪 We did it.

Conclusion

We are now able to add all 4 modules into TheAwesomeApp.

All developers of 4 modules now can work independently without code conflict, long build times etc.

Fork full source code here: TheAwesomeApp, Pay, Play, Chat, Shop.

--

--