Swift package manager dependencies

I have a PackageA that uses swift code and has a dependency on a PackageB that also uses swift code only.
In the main hosting app, I would like to just import PackageA and use the classes of PackageA and also PackageB. Is this possible somehow?
I did set the proper access levels (public) in both of the packages. but importing PackagaA in my main app does not let me use the classes from PackageB. I have to import the PackageB to make it work

note: packages are local.
Any help appreciated.

There are a few options:

  1. You can expose PackageB's classes as type aliases in PackageA. There may be subtleties with this approach in terms of what API actually ends up available.
  2. You can use @_exported import PackageB in PackageA, though this is functionality has not made it through Swift evolution and may not function correctly in all cases, it also may change if it eventually goes through evolution.
  3. If your API is small, you could simply wrap the parts you need in PackageA so the PackageB dependency is hidden.

Hi @George !
Thanks for the reply.

The type aliases could be okay-ish if my codebase would be small. I was reading also about the @_exported, but as you say, the underscore explicitly marks that it's not finished. Don't want to build on top of that as a 'hack' .
I was also thinking about the 3rd option that you suggested, but again, for small API could be okay, it depends on codebase size and complexity.

I was thinking if there is some SPM. Project setting or a headers "hack", allowing us to expose the lower packages to the main app where the the parent package is utilised.

I am not sure if this is by the design or such feature will come to the SPM later?

@George once again, thanks for your reply and input :slight_smile:

I have found that Firebase in their swift package are exporting underlying modules through one import Firebase in the containing app.

When I open the import Firebase in Xcode, I can see it imports:

import FirebaseCore
import FirebaseCrashlytics
import FirebaseInstallations
import FirebaseRemoteConfigInternal

so it looks like they have solved to include couple of swift PM targets into a single one. But I yet don't understand how. I tried to reproduce it on my own, but failed to do so. The classes are unreachable just by import PackageA in my example.