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.
Uh oh!
There was an error while loading. Please reload this page.
-
Using
swift-dependenciesin a modular architecture, the recommended method for defining a Key without its definition is to use theTestDependencyKeyProtocol.There is a gotcha using this method, though:
When declaring the
testValueof a dependency usingTestDependencyKeyin a Module A. If you try to declare a differentpreviewValuealongside theliveValueimplementation in yourDependencyKeyimplementation in module B. ThetestValuefrom module A will be used as apreviewValueregardless.What could be done about it ?
TestDependencyKeyprotocol, the previewValue of theDependencyKeyprotocol or somewhere in the readme ?previewValuerequirement from theTestDependencyKeyprotocol 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
previewValuealongside theliveValueinstead of thetestValuein a modular architecture makes less sense than I originally thought.TestDependencyKeybe divided into 3 definitions ?TestDependencyKey,PreviewDependencyKeyand aTestAndPreviewDependencyKeythat 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