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"))
}
}