Last active
March 4, 2019 03:07
-
-
Save superarts/3b081043df427c69d1331ddad6d20135 to your computer and use it in GitHub Desktop.
Provide test only feature in Test target
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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