Last active
September 22, 2023 15:27
-
-
Save SmartJSONEditor/33d4791416e7b47666c12c3cde4ca96e to your computer and use it in GitHub Desktop.
This file contains 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
class ViewModel: ObservableObject { | |
@Published public var title: String | |
deinit { | |
print("deinit ViewModel") | |
} | |
init(title: String) { | |
self.title = title | |
print("init ViewModel") | |
} | |
} | |
struct ContentView: View { | |
/// View Owns object | |
@StateObject var viewModel: ViewModel | |
/// Passing some injected values | |
init(title: String) { | |
_viewModel = StateObject(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