В коде это будет выглядеть так:
import SwiftUI
import PlaygroundSupport
struct MyTextView: View {
@State private var text1: String = "Some Content"
@State private var text1Placeholder: String = ""
@State private var text2: String = ""
var body: some View {
VStack(alignment: HorizontalAlignment.center, spacing: 20) {
Image(systemName: "circle")
TextField( self.$text1Placeholder.wrappedValue, text: $text1, onEditingChanged: { (editing) in
if editing {
self.$text1Placeholder.wrappedValue
= self.$text1.wrappedValue
self.$text1.wrappedValue = ""
}
})
TextField("Text Field 2", text: $text2)
.border(Color.green)
}.padding()
}
}
PlaygroundPage.current.liveView = UIHostingController(rootView: MyTextView())