Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created June 7, 2023 09:30
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/02debaf249d87263cf5a69c3b421ddc6 to your computer and use it in GitHub Desktop.
Save laevandus/02debaf249d87263cf5a69c3b421ddc6 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@StateObject private var viewModel = ContentViewModel()
var body: some View {
VStack {
Text(viewModel.title)
TextField("Username", text: $viewModel.username)
.textFieldStyle(.roundedBorder)
}
.padding()
}
}
final class ContentViewModel: ObservableObject {
@Published 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