Replies: 1 comment
-
Have you tried to have a singleton wrapped as a dependency? I use dependency to access a framework with a bunch of services and states in singleton(s). So if your singleton can store references to instance(s) of VideoPlayer and such, you can wrap it in dependency and access via it. Here is abbreviated version of how I use it: public protocol ATConfigDependency {
var primaryUserAccount: ATUserAccount? { get }
}
public struct ATConfigClient_Live: ATConfigDependency {
public var primaryUserAccount: ATUserAccount? {
return ATSDK.config.primaryUserId
}
} Note: I usually have a separate method to update such objects, something like And later on: @Dependency(\.config) private var config
{
print(config.primaryUserAccount)
} |
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Some views in SwiftUI require long-lived reference types such as VideoPlayer which expect to receive an AVPlayer. While I can retain these objects locally within views typically using something like @StateObject my goal is to have the same object accessible via a dependency so that I can play with it (for various reasons: like stop/play video) as well. I'm curious if anyone has come across or can provide examples of how to address this in The Composable Architecture. Any insights or examples would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions