Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active June 8, 2023 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/f20438e10fc29579c63463a74a2310b9 to your computer and use it in GitHub Desktop.
Save laevandus/f20438e10fc29579c63463a74a2310b9 to your computer and use it in GitHub Desktop.
import Observation
import SwiftUI
struct ContentView2: View {
@Bindable private var viewModel = Content2ViewModel()
var body: some View {
VStack {
Text(viewModel.title)
TextField("Username", text: $viewModel.username)
.textFieldStyle(.roundedBorder)
}
.padding()
}
}
@Observable class Content2ViewModel {
var username: String = ""
var title: String {
if username.isEmpty {
return "Hello, world!"
}
else {
return "Hello \(username)!"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment