Skip to content

Instantly share code, notes, and snippets.

@superarts
Last active March 4, 2019 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superarts/3b081043df427c69d1331ddad6d20135 to your computer and use it in GitHub Desktop.
Save superarts/3b081043df427c69d1331ddad6d20135 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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