Search code examples
swiftuidatepicker

Value of type '(UIDatePicker) -> ()' has no member 'date' In swift 5


Im trying to capture date to a variablew outside of funciton but I keep getting this message :

Value of type '(UIDatePicker) -> ()' has no member 'date'

This is the code

var selectedDate: String?

@IBAction func datePicker(_ sender: UIDatePicker) {
    selectedDate = self.datePicker.date
}

Solution

  • You are calling the function itself which makes no sense unless there is also an outlet datePicker.

    Use the sender parameter

    @IBAction func datePicker(_ sender: UIDatePicker) {
        selectedDate = sender.date
    }
    

    and declare selectedDate as Date

    var selectedDate: Date?