-
-
Save laevandus/f20438e10fc29579c63463a74a2310b9 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
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