1

I am looking to find unused imports in an umbrella architecture. The imports are used within swift files. These files receive their imports from Objective-C headers so a text based search would not work. I wrote a script that searches for imports and checks if they are used within the class through text. But the issue is that some imports do not have to be explicitly stated. For example, if we have a framework foo that we use by:

import foo

and that framework has

#import <Example/Example.h>

in its own umbrella header foo.h. I have access to Example, without explicitly importing it.

So the issue is that we cannot see if an import is unused because it does not have to be explicitly imported. Is there a way we can detect unused imports?

I created a text based script in python that searches through a code base and checks for imports that are not used. It would go through directories and look for specific imports, and if they are present check if they are actually being used within the class. I expected that this would work without considering the umbrella architecture. But because there are scenarios where imports do not have to be explicitly stated, this did not work.

  • You can comment everything in the umbrella header, then resolve issues during build – Cy-4AH Feb 03 '23 at 11:01
  • I thought of that but that isn't a viable option because the build time would take a significant amount of time, it wouldn't be plausible. – waysayheal16 Feb 04 '23 at 18:00

0 Answers0