Hi guys,
My library is composed by two modules:
This is the structure

Now in order to compile it in SPM I need to create two targets:
import PackageDescription
let package = Package(
name: "MyLib",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "MyLib",
targets: ["MyLib"]),
],
dependencies: [],
targets: [
.target(
name: "CHTMLSAXParser",
dependencies: []),
.target(
name: "MyLib",
dependencies: ["CHTMLSAXParser"])
]
)
This is pretty straightforward (and required because I can't mix both ObjC and Swift in the same module): in MyLib a source swift file call import CHTMLSAXParser and everything works fine.
However I don't know what's the correct way to replicate the same behaviour with CocoaPods podspec file.
Any idea?
In CocoaPods, you can either create two separate pods for your targets (with separate .podspecs), or just mix the ObjC and Swift sources together, as CocoaPods doesn't have that limitation you mentioned.
The best solution maybe to include the same sources in a single package but one file import CHTMLSAXParser and I don't know how to suppress this in case of cocoapods and keep it in case of SPM.
The alternative seems better but can I reference another local podspec from inside the main library podspec?
Maybe try #if canImport(CHTMLSAXParser)?
You can, but not by :path as :path is not available within podspecs. If you are not planning on publishing your main podspec then just type s.dependency 'MyLocalPod' and then ensure do add in your Podfile pod 'MyLocalPod', :path => '../path/to/MyLocalPod.podspec' so that CocoaPods knows where to find it from.
I'll publish the pod. By the way @igor-makarov suggestions worked like a charm.
Just to recap: the limit with mixed Swift-ObjC code does not apply to CocoaPods packages so I'll integrate all inside the same module.
My podspec, just for reference, is this:
Pod::Spec.new do |s|
s.name = "MyLib"
...
s.source_files = "Sources/**/*"
s.ios.public_header_files = 'Sources/**/*.h'
s.xcconfig = {
'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2',
'OTHER_LDFLAGS' => '-lxml2'
}
s.frameworks = "Foundation"
s.swift_versions = ['5.0', '5.1', '5.3']
end
When imported from CocoaPods I'll not need of import CHTMLSAXParser (the second module) so I can bypass it using #if canImport(CHTMLSAXParser)?:
#if canImport(CHTMLSAXParser)?
import CHTMLSAXParser
#endif
Thank you guys 馃憤