🎛️DatePicker
👉 SwiftUI Tutorials ⟩ Working with UI Controls ⟩ Sec 3. Define the Profile Editor
var dateRange: ClosedRange<Date> {
    let min = Calendar.current.date(byAdding: .year, value: -1, to: profile.goalDate)!
    let max = Calendar.current.date(byAdding: .year, value: 1, to: profile.goalDate)!
    return min...max
}
DatePicker(
    selection: $profile.goalDate,
    in: dateRange,
    displayedComponents: .date
) {
    Text("Goal Date").bold()
}Last updated
Was this helpful?