0

This must be obvious, but I just don't get it.

I'm trying to write a function where the values of a UIDatePicker and a UIPickerView (for seconds) need to be checked for nil (in case one of them is still spinning). So I had:

let datePicker = view.viewWithTag(9) as! UIDatePicker

if datePicker.date != nil {

}

For which I get a Binary operator '!=' cannot be applied to operands of type 'NSDate' and 'NilLiteralConvertible.

HansiOber
  • 317
  • 2
  • 13
  • datepicker.date is always set because it is of type NSDate and not NSDate? So if you want to check for spinning have a look here: http://stackoverflow.com/questions/5055688/detect-if-uidatepicker-is-rolling – kutschenator Oct 05 '15 at 19:20
  • Thank you! Should I delete the question? – HansiOber Oct 05 '15 at 19:30
  • dont know the best way to handle this. deleting is always bad, it removes information that might be needed... i will just add my comment as an answer and then you can accept it – kutschenator Oct 05 '15 at 19:33

1 Answers1

1

datepicker.date is of type NSDate, not NSDate?. (see documentation) That's why you cannot check if it is nil because it is not an optional.

If you want see if it is still spinning refer to this question: Detect if UIDatePicker is rolling?

Community
  • 1
  • 1
kutschenator
  • 902
  • 10
  • 26