Replies: 1 comment 4 replies
-
Yeah this does seem like a gotcha, but also I don't think it's a bug. I think this is the intended behavior as far as Swift is concerned. You aren't allowed to extend a protocol with default implementations from another module. I will look into improving the documentation, but I don't think there's really anything we should do in the library itself. Adding even more protocols is too heavyweight, and I think by far the most common use case is to define the Can you explain a bit more why you wanted to define the |
Beta Was this translation helpful? Give feedback.
-
Using
swift-dependencies
in a modular architecture, the recommended method for defining a Key without its definition is to use theTestDependencyKey
Protocol.There is a gotcha using this method, though:
When declaring the
testValue
of a dependency usingTestDependencyKey
in a Module A. If you try to declare a differentpreviewValue
alongside theliveValue
implementation in yourDependencyKey
implementation in module B. ThetestValue
from module A will be used as apreviewValue
regardless.What could be done about it ?
TestDependencyKey
protocol, the previewValue of theDependencyKey
protocol or somewhere in the readme ?previewValue
requirement from theTestDependencyKey
protocol and replacing it with the same method that was used to access the live value and it worked as expected.Still, I'm not sure this is the correct answer in terms of ease of use. Now that I had time to think about it, the idea of specifying a
previewValue
alongside theliveValue
instead of thetestValue
in a modular architecture makes less sense than I originally thought.TestDependencyKey
be divided into 3 definitions ?TestDependencyKey
,PreviewDependencyKey
and aTestAndPreviewDependencyKey
that would combine them both ?Here is a sample kindly provided by @tgrapperon that helped me look into the issue 😊
DependencyPreview.zip
Beta Was this translation helpful? Give feedback.
All reactions