-
-
Save laevandus/02debaf249d87263cf5a69c3b421ddc6 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
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