Since SPM doesn't support mixed language targets, I have to split the ObjectiveC files into a separate target.
let package = Package(
name: "MyPackage",
products: [
.library(
name: "MyPackage",
targets: ["MyPackage"]),
],
targets: [
.target(
name: "MyPackage",
dependencies: ["ObjCTarget"]),
.target(name: "ObjCTarget"),
.testTarget(
name: "MyPackageTests",
dependencies: ["MyPackage"]),
]
)
This requires me to import ObjCTarget
in the Swift files of the main MyPackage
target. When I add it everything works fine for SPM.
However, if I wish to continue with support for CocoaPods I get No Such Module
error since Cocoapods bundles them into one target. What is the solution?
This seems to do the trick:
#if !COCOAPODS
import ObjCTarget
#endif
Works with both managers now.