Reputation: 25348
I've got a form in SwiftUI where one of the fields in a Double.
If I set @State private var qty: Double = 0
then the form field, naturally, has a default of 0
. But when adding a new item, I want that field to just be blank.
If I just remove the default and make it @State private var qty: Double
, then an error is thrown.
Upvotes: 0
Views: 698
Reputation: 20066
How about making the property optional?
struct ContentView: View {
@State private var amount: Double?
var body: some View {
VStack {
TextField("Amount", value: $amount, format: .number)
.keyboardType(.decimalPad)
}
.padding()
}
}
Upvotes: 1