I want to send a network request whenever the user has chosen a new date from the DatePicker. How do I capture that event?
onChange does this on iOS 14. Still haven’t found iOS 13

You can use onChange:
struct ContentView: View {
@State var selectedDate = Date()
var body: some View {
Form {
DatePicker("Date", selection: $selectedDate)
.onChange(of: selectedDate) {
print($0)
}
}
}
}
Use onReceive instead:
import Combine
import SwiftUI
struct ContentView: View {
@State var selectedDate = Date()
var body: some View {
Form {
DatePicker("Date", selection: $selectedDate)
.onReceive(Just(selectedDate)) {
print($0)
}
}
}
}
Note that onReceive fires also when a view is initialised.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With