import SwiftUI class UserData: ObservableObject { @Published var name: String = "John Doe" } struct UserView: View { @StateObject var userData: UserData var body: some View { VStack { Text("Hello, \(userData.name)") TextField("Enter your name", text: $userData.name) } } } struct ContentView: View { var body: some View { UserView(userData: UserData()) } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter