Skip to content

Instantly share code, notes, and snippets.

@SmartJSONEditor
Created September 22, 2023 15:31
Show Gist options
  • Save SmartJSONEditor/f33ed6707a3981d7c740e25a85ed17c8 to your computer and use it in GitHub Desktop.
Save SmartJSONEditor/f33ed6707a3981d7c740e25a85ed17c8 to your computer and use it in GitHub Desktop.
@Observable
class ViewModel {
public var title: String
deinit {
print("deinit ViewModel")
}
init(title: String) {
self.title = title
print("init ViewModel")
}
}
struct ContentView: View {
@State var viewModel: ViewModel
/// Passing some injected values
init(title: String) {
_viewModel = State(wrappedValue: ViewModel(title:title))
}
var body: some View {
VStack {
Text(viewModel.title)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment