Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import another package along with a SPM Library

Imagine this scenario when your App project uses two custom libraries

.xcworkspace
|- App.xcodeproj
|- LibraryA.xcodeproj
|- LibraryB.xcodeproj

And since in this case we are working with Xcode frameworks one could add the following to the LibraryB header file:

#import <LibraryA/MyLibraryA.h>

and now not only there is no need to import LibraryA in the source od LibraryB, but also every time you import LibraryB inside your App source files, the LibraryA gets imported along with it, which can be very convenient.

The same applies to the default Foundation import one can find in an Xcode framework header:

#import <Foundation/Foundation.h>

Now with SPM, I need to manually import Foundation everywhere I use it.

Q: Is this possible to achieve the same result when using SPM packages exclusively?

I haven't found any resources on this matter. Thanks!

like image 681
Witek Bobrowski Avatar asked Dec 10 '20 11:12

Witek Bobrowski


1 Answers

To expose import to your whole package you can use @_exported attribute inside of any of your swift file:

@_exported import Foundation

More info about this in next discussion: https://forums.swift.org/t/package-manager-exported-dependencies/11615

like image 186
iUrii Avatar answered Oct 12 '22 06:10

iUrii