Created
December 18, 2019 19:57
-
-
Save filimo/c2552bd7c3f377040681271e6f4ae5ea to your computer and use it in GitHub Desktop.
How to separate Global Store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import PlaygroundSupport | |
class GlobalStore: ObservableObject { | |
static let shared = GlobalStore() | |
private init() {} | |
@Published var api1 = Api1Store() | |
@Published var api2 = Api1Store() | |
} | |
class Api1Store { | |
var field = "" | |
} | |
class Api2Store { | |
var field = "" | |
} | |
struct Test: View { | |
@ObservedObject var store = GlobalStore.shared | |
var body: some View { | |
VStack { | |
TextField("api1 field", text: $store.api1.field) | |
TextField("api1 field", text: $store.api1.field) | |
Divider() | |
TextField("api2 field", text: $store.api2.field) | |
TextField("api2 field", text: $store.api2.field) | |
} | |
} | |
} | |
let viewController = UIHostingController(rootView: Test()) | |
PlaygroundPage.current.liveView = viewController |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment