6

Currently we have modularized our Swift project, using multiple targets. The targets compile to .framework files that are dependencies of the higher targets. We have a Common module target, a few Product module targets, and the original App target. Common will hold very low level code, shared libs, and any specific code that may be shared by multiple product targets.

So the App will do:

 import Common
 import Product1
 import Product2

And Product1 target code might do:

 import Common

Generally the flow is Common -> Product* -> App, where Common will never reference the other direction.

Unfortunately Common has grown large, and has a lot of code that may not be needed for every import.

What I'd like to be able to achieve in Swift, is something like this:

import Common.API
import Common.PurchaseCheckout

I've looked into module-maps, which allow for setting up the import submodules, but it is all focused around objective-c headers, and not Swift. Is there a swift variation?

The specific need is that we want to create a light-weight SDK that only uses some of the features, and as soon as we "import Common", it bloats the SDK, and it adds dependencies on quite a few unrelated cocoa-pods also. We can include files in the SDK target file-by-file, but were hoping modularization would make things simpler.

EDIT

It appears I can use such things as:

import class Common.FileDownloadAPI
import class Common.FileUploadAPI

possibly in my code to create the impression of a partial import. However, modulemaps seem to be a way in objective-c to do this for you, creating the submodule. I do not want to have to write 100 class imports to import half of the 200 files that a submodule might do in one import. So still looking for ideas.

Miro
  • 5,085
  • 1
  • 33
  • 59
  • Possible duplicate of [Submodules in Swift](https://stackoverflow.com/questions/31625447/submodules-in-swift) – Tony Lin May 23 '18 at 13:29

0 Answers0