I want to use datepicker in textfield for select date of birth.
You should have said you wanted to do in SwiftUI.
Have a look here (even though it has some errors but it shows the principles)
This works:
struct ContentView: View {
var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.dateStyle = .long
return formatter
}
@State private var birthDate = Date()
var body: some View {
VStack {
Text("Select a date")
DatePicker(selection: $birthDate, in: ...Date(), displayedComponents: .date) {
Text("date")
}
Text("Birth date is \(birthDate, formatter: dateFormatter)")
}.labelsHidden()
}
}