Importing Swift libraries from Objective C++

How can you import a Swift target built with Swift Package Manager from an Objective C++ source?

Based on Apple Developer Documentation, #import <module/module-Swift.h> works in CocoaPods, but not in Swift Package Manager.

Any suggestions and/or examples about using Swift language Swift package from Objective C++?

2 Likes

SPM doesn't support generating the header. If the API is sufficiently simple you can write the header yourself (e.g. in our tests we define a class in Swift and then manually declare the bits we need to use from objc). If the target is too complicated for this but supports a non-SPM build, you could build it with that and then copy the generated header to your source tree and import that (and then remember to keep it up-to-date when you update the library).

1 Like