Creating an Objective-C package for SPM

I'm getting stuck retrofitting a framework I created that supports Carthage to also support Swift Package Manager. The problem is with a single helper method for catching NSExceptions that is written in Objective-C. All of the other files in the framework are written in Swift.

I have pulled the source files that provide that method and tried 1) adding the ObjC files as a separate target defined in the package (and a separate folder for its two source files), and 2) creating a completely separate package that the main package uses as a dependency.

In either case, once I get the package to build successfully in Xcode, I get error messages stating that the module does not exist, and Control-clicking on an import statement for the Objective-C dependency takes me to a blank screen. This leads me to believe that I have probably set up the Objective-C package incorrectly, but I have been having a very difficult time finding any documentation for how it should be set up.

I wonder if anybody in this forum can help me find some documentation, point me to a simple example of a mixed language SPM distribution, or otherwise suggest how to fix this problem.

Either of those should have worked, so something else is complicating the issue. More context might help. Is it open source? Can you provide a link?

I pushed my latest attempts to make this work to a branch named "exceptions" at https://github.com/dennisbirch/dbbbuilder-swift/. With all the back and forth it has gone through to troubleshoot the different approaches, the workspace is a bit of a mess. But if you open the "DBBBuilder" folder from within Xcode, you can experience what I've been seeing in attempting to get this work as an SPM package. I appreciate your taking a look at it.

You haven't exposed any public functionality for the Objective C module, so I'm guessing the compiler isn't synthesising a module map. C-language targets need to have an include directory which exposes the public headers files, or you need to provide your own module map. You can read about that at the SwiftPM docs. Once you add that, that should fix the compilation errors

Thanks Tim. That got me much farther down the road!

Terms of Service

Privacy Policy

Cookie Policy