Why does Swift's TextField take in a title if it's not used?

Viewed 48

I noticed the first argument of TextField takes in a "title", but to me, this string is never used. I don't see it displayed on the simulator.

I suspected maybe it is just as a unique ID for that TextField, but it's not because I duplicated it and it build. Plus the "title" name doesn't really match that description.

I was wondering what the purpose of the parameter was or how to access it for display? Thanks!

struct ContentView: View {
    
    @State private var checkAmount = 0
    
    var body: some View {
        NavigationView {
            Form {
                Section {
                    TextField("Check amount", value: $checkAmount, format: .currency(code: Locale.current.currencyCode ?? "USD"))
                }
                Section {
                    Text("Input")
                }
            }  .navigationTitle("Tabshare")
        }
    }
}
1 Answers
  1. Please don't forget about accessibility - specifically with screen readers and Voice Control. Adding a description of a text field is crucial for people that use these features.

  2. Don't forget that SwiftUI is cross-platform — macOS heavily utilises Text Field titles.

Text Field example with titles

Related