Dependencies and the delegate pattern #358
Unanswered
pieterjongsma
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am curious what would be the recommended way to implement a delegate pattern for a dependency. I couldn't find the pattern in any of the library provided dependencies and the right choice does not seem obvious to me.
I'm dealing with WCSession/WCSessionDelegate in my code. I've created a
WatchConnectivityManager
struct as aDependencyKey
with functions such asvar transferFile: @Sendable (_ url: URL, _ metadata: FileTransferMetadata?) -> Void
.I would also like to be notified when file transfers arrive and so I've created a
WatchConnecitivityDelegate
class for that, implementingfunc session(_ session: WCSession, didReceive file: WCSessionFile)
. When constructing theliveValue
, I instantiate and assign the delegate to theWCSession
.How do I now bubble up the messages to, for example, a database?
Some options I've considered:
onFileReceived
function on theWatchConnectivityManager
dependency to be overridden (not possible, because the dependency is a struct/read only?)WatchConnectivityDelegate
None of those seem great to me. I would really appreciate some hints on how to best implement this.
I'm not using Composable Architecture but am attempting to implement according to the Modern SwiftUI episodes on pointfree.co
Beta Was this translation helpful? Give feedback.
All reactions