@State private var fieldNames = ["name", "age", "email"]
@State private var dictionary: [String: String] = [:]
VStack {
ForEach(fieldNames, id: \\.self) { fieldName in
TextField("Enter \\(fieldName)", text: $dictionary[fieldName] ?? "")
}
// Additional views or actions
}
Button("Show Values") {
print(dictionary)
}
import SwiftUI
struct ContentView: View {
@State private var fieldNames = ["name", "age", "email"]
@State private var dictionary: [String: String] = [:]
var body: some View {
VStack {
ForEach(fieldNames, id: \\.self) { fieldName in
TextField("Enter \\(fieldName)", text: $dictionary[fieldName] ?? "")
}
Button("Show Values") {
print(dictionary)
}
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}