import SwiftUI // Capítulo 4: Creando nuestros propios Property Wrappers @propertyWrapper struct UpperCase { private(set) var value: String var wrappedValue: String { get { value } set { value = newValue.uppercased() } } init(wrappedValue: String) { self.value = wrappedValue.uppercased() } } struct User { @UpperCase var name: String } struct UserView: View { @ObservedObject var user: User var body: some View { VStack { Text("Hello, \(user.name)") TextField("Enter your name", text: $user.name) } } } struct ContentView: View { var body: some View { UserView(user: User(name: "John Doe")) } }
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