I write a framework and I like to divide framework to small separate submodules (targets). Apple provides a cool description for thing I want to achieve with CocoaPods:
Targets are the basic building blocks of a package. A target can define a module or a test suite. Targets can depend on other targets in this package, and on products in packages which this package depends on.
I could easily do it with Swift Package Manager:
targets: [
.target(name: "Network"),
.target(name: "Service", dependencies: ["Network"])
],
I could use import Network
in a Service
target and it's cool because they are separate modules, logic is clear.
How to achieve it in CocoaPods and Carthage (I write a framework, not the final application)?
What I've tried:
Subspec
I tried to use subspecs:
s.subspec 'Service' do |ss|
ss.dependency 'MyFramework/Network'
ss.source_files = 'Sources/Service/**/*.swift'
end
s.subspec 'Network' do |ss|
ss.source_files = 'Sources/Network/**/*.swift'
end
It doesn't work as I want because CocoaPods just merges all files into one framework (just divides it to separate folders), so:
- I receive namespace collisions.
- Fatal error when I try to
import Network
insideService
because there is noNetwork
target afterpod install
. So I can't use one that framework with Swift Package Manager. CocoaPods just merges everything to one targetMyFramework
as I mentioned before.
Separate repos/pods
It's the solution but it's very hard to maintain multiple separate git repositories and make separate commit and pushes. I want to keep everything in a one repo.