Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to best modularize an Xcode project to speed up building

I work in a team on an iOS project that has grown to enormous size in terms of Swift code.

It takes about 10 minutes to build the project from the clean state and, most scrutinizing, 30 seconds to build and run the project after changing anything in the code, even if that code pertains to a single line in a private method in Swift file symbols from which are not used anywhere else.

We've tried lots of thing to improve build times, including techniques from this nice resource https://github.com/fastred/Optimizing-Swift-Build-Times Nothing helped, you still need to wait the whole 30 seconds after changing every minor thing to see it in the app.

We use Xcode 10, the "New build system" with the compilation mode set to Incremental. If I build the project via Perform Action > Build With Timing Summary, the longest phase is "Swift code compilation" which is nothing new. We suspect that Xcode tries to follow conservative compilation decision making and rebuilds every Swift file that could potentially have any connection to the modified Swift code. And it seems that Xcode is wrong most of the time and does redundant work.

I kinda miss Objective-C days when the compiler would look at the all import/include statements and only rebuild explicitly declared dependencies, which meant blazing fast build times.

So I now think that maybe we could break our project into modules and ubiquitously use import in Swift to tell the compiler what Swift files depend on what other Swift files.

Is there a good and perhaps automated way to modularize a big project into many small components to speed up regular lets-try-how-it-works builds?

like image 773
Desmond Hume Avatar asked Oct 22 '18 11:10

Desmond Hume


Video Answer


1 Answers

  1. You can split your projects into Cocoa Touch Frameworks. -> https://www.raywenderlich.com/5109-creating-a-framework-for-ios
  2. Add each framework to its own git repo. It may be private repo.
  3. Create private cocoapods. -> https://guides.cocoapods.org/making/private-cocoapods.html
  4. Add new dependencies to your project podfile. -> pod 'YourFramework', :git => 'FrameworkGitRepoPath'
like image 152
RahmiBozdag Avatar answered Oct 08 '22 17:10

RahmiBozdag