I'm working on my first SwiftUI app, and have implemented a Form with one of the fields being a DatePicker. However, this value is completely optional. So, it is possible that the user doesn't enter a value at all. I'm unable to figure out, though, how I can make it so that the user doesn't need to enter the value. The code itself is rather simple:
DatePicker(selection: $expirationDate,
displayedComponents: .date) {
Text("Expiration")
}
Is there a way so that I can indicate that $expirationDate can have a Date or can be nil? The DatePicker by default seems to set the value to the current Date and I couldn't figure out a way to override that behavior. Thoughts?