As of my final replace, Swift Bundle Supervisor (SPM) doesn’t help conditional dependencies based mostly on construct configurations straight, much like how CocoaPods does with the :configurations possibility. Nonetheless, there are a number of workarounds you’ll be able to think about to attain the same impact:
1. Utilizing Conditional Compilation: You’ll be able to conditionally embody the package deal based mostly on compiler flags or construct settings. For instance, you might outline a compiler flag for debug builds and use it to conditionally import the package deal. Nonetheless, this strategy requires modifying your code and might not be very best if you wish to preserve your package deal dependencies separate out of your codebase.
#if DEBUG
import PackageA
#else
import PackageB
#endif
2. Utilizing Totally different Targets: One frequent workaround is to create a number of targets in your venture, every with its personal set of dependencies specified within the Bundle.swift file. You’ll be able to then conditionally construct and run totally different targets based mostly in your construct configuration.
let package deal = Bundle(
identify: “MyProject”,
targets: [
.target(
name: “MyTarget”,
dependencies: [
.product(name: “PackageA”, package: “MyPackage”),
]
),
.testTarget(
identify: “MyTargetTests”,
dependencies: [“MyTarget”]),
]
)
You’ll be able to create separate schemes in Xcode for various construct configurations, every of which builds a distinct goal.
3. Utilizing Script Phases: You’ll be able to create customized construct script phases in Xcode to conditionally add or take away the package deal from the venture in the course of the construct course of. This strategy requires some scripting information and could also be extra advanced to arrange and keep.
if [ “$CONFIGURATION” == “Debug” ]; then
swift package deal resolve
else
swift package deal resolve –version x.y.z
fi
Every of those approaches has its personal trade-offs by way of complexity, maintainability, and adaptability. You may want to decide on the one that most closely fits your venture’s necessities and constraints.