"Simulator" as an additional context #356
pieterjongsma
started this conversation in
Ideas
Replies: 2 comments
-
Hi @pieterjongsma, there are two ways you can handle this in the library today. In your entry point you can override any dependencies a single time, globally, using @main
struct MyApp: App {
init() {
#if TARGET_IPHONE_SIMULATOR
prepareDependencies {
$0.client = MockClick()
}
#endif
}
…
} Or you can perform this struct Client: DependencyKey {
#if TARGET_IPHONE_SIMULATOR
static var liveValue: Client { … }
#else
static var liveValue: Client { … }
#endif
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
@mbrandonw Ah, thank you! Out of curiosity: you don't think a special value for the simulator has a place in the library, just like |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using the Dependencies library to control my WatchConnectivity dependency. This is working great in previews and testing. When running in the Simulator, the Dependencies library will of course pick the
liveValue
. However, there are some functions in WatchConnectivity that do not work in the simulator, like transferring files. This breaks a lot of functionality in my app. I was wondering if I could use the Dependencies library to use a mock implementation for those specific functions.Is there a way to overwrite dependencies when running in the simulator using
withDependencies
or another function? I've tried using it inApp.init
, but this affects how I can set the App's instance variables (can no longer assign tolet
).If not, would you consider adding the simulator as an additional context in the Dependencies source code (defaulting to
liveValue
)? I would be happy to try my hand at the implementation.Beta Was this translation helpful? Give feedback.
All reactions