-
Hi! I'm trying to figure out how to best use Dependencies and I've defined a CoreBluetooth wrapper using Swift Concurrency and Dependencies as (some of) the following: extension ConnectionManager: DependencyKey {
public static let liveValue: ConnectionManager = {
…
}()
}
extension ProductManager: DependencyKey {
public static let liveValue: ProductManager = {
@Dependency(\.connectionManager)
var connectionManger
…
}()
} When declaring my tests, I tried the following (as seen in the docs) @MainActor
final class ConnectionManagerTests: XCTestCase {
@Dependency(\.connectionManager)
var connectionManager
override func invokeTest() {
withDependencies {
$0.connectionManager = .liveValue
} operation: {
super.invokeTest()
}
}
…
} When trying to build and run the tests, I alway get the same issue with the following log:
I'm not quite sure what I did wrong here, since I already tried using the I'm not using TCA for this specific dependency, yet, because I'd rather focus on the dependency's behavior rather than its implementation inside a feature at the moment. Any help is much appreciated! 😅 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@Pomanks I think we may need more info to help diagnose. Do you have a project that reproduces the problem you can share? A linker error may just point to not linking a target to the Dependencies framework as the build system requires. For what it's worth it should be possible to use Dependencies outside of TCA just fine, and in fact our Standups sample app does just that. |
Beta Was this translation helpful? Give feedback.
-
@stephencelis following the advice
I was able to get rid of the previous linker error! I think I got confused by the note from the following docs 😅 I still have another issue though. I made both my libraries inside the package as To help you diagnose and as requested, I've added you (and @mbrandonw) in a sample project showing the current behavior. |
Beta Was this translation helpful? Give feedback.
Hi @Pomanks, thanks for the sample project. That helps us see what is going on.
Unfortunately you have a pretty complex set up right now, and if you trace through everything, what you are experience is to be expected. The
productManager
is depending on theconnectionManager
at the moment of access of theliveValue
, which means the mere act of trying to override the dependency to the live value resolves theconnectionManager
, which has no choice but to choose thetestValue
since it has not yet been override to itsliveValue
.I can think of 3 options to work around this.
This first is the most work, but I think it's probably the most correct. While it is ok to bind the
@Dependency(\.conne…