Help understanding XCode decide what file to compile behavior

After my project deploy finish, I come back to revise why our project is compiling so slow there are 3 categories of suggestions on Web:

  1. Project Setting Tweak
  2. Modularization
  3. Source Code line by line tweak
    and all of them are measuring by BuildTimeAnalyzer/Build with Timing Summary.

I find there are no any article describing viewing point of "after I edited a .swift file, how many .swift will be recompile". Currently my checking this by steps:

  1. Changing the line "private var a = 2" to "private var a = 3"
  2. Go to XCode -> Show the Report Navigator -> Compile Swift source files -> checking number of line "Compile xxxx.swift"

screenshot: https://imgur.com/a/9rMwTsV (Checking number of compile files)
project: https://drive.google.com/file/d/1Jh5V_sRZKiy7RO2CWAgxwpNRSuqnbyXe/view?usp=sharing

Through my trial and error, I found that: if any .swift contains any reference of R struct, and after I did any changes making the R.generated.swift rebuild, those .swift will rebuild.

My guessing is that:

R structure is a dependency all ViewController.swift, and R struct has the interface of every ViewController through struct storyboard.
Changing any of these ViewController.swift will make XCode think these ViewController interface change,
then XCode decides that R structure has an interface change due to R structure expose these ViewController as one of the storyboard struct.
and last, all files that contain R struct will recompile because R has an interface change.

I can improve the number of compiling file number by Modularization, spliting R struct into smaller R struct by Module-basic, and making them into a .Framework and link in Main Target.

Assuming I want to archive both targets of

  1. less file compile = less build time
  2. all benefit of static resource mapping bring

Is Modularization the only solution?

Before I decide to use R.swift library, actually I am very impressed by AndroidStudio auto-generating R structure after I saved any .xml file.
I noticed that in AndroidStudio, Whenever I edited AAcitivy.java, Android Studio recompiling only AAcitivity.java. I don't understand how XCode decide to build more files if it is using swift langauge, comparing to a similar strucutre created in Android Studio?

Terms of Service

Privacy Policy

Cookie Policy