Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Provide test only feature in Test target
protocol ProductionFeatureProtocol: TestFeature1, TestFeature2 {
}
struct DefaultProductionFeature: ProductionFeatureProtocol {
}
protocol TestFeature1 {
func testOnly1()
}
extension TestFeature1 {
func testOnly1() {
print("Default test feature1")
}
}
protocol TestFeature2 {
func testOnly2()
}
extension TestFeature2 {
func testOnly2() {
print("Default test feature2")
}
}
let feature = DefaultProductionFeature()
feature.testOnly1()
feature.testOnly2()
extension DefaultProductionFeature {
func testOnly1() {
print("Overrided test feature1")
}
func testOnly2() {
print("Overrided test feature2")
}
}
@superarts

This comment has been minimized.

Copy link
Owner Author

@superarts superarts commented Mar 4, 2019

The problem of this approach is that extension DefaultProductionFeature cannot be declared in another module, i.e. Test target.

The reason is that when a module is compiled, its context has been resolved already, and cannot be altered from outside. Read more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment