I can't find the way to set Date type variables to initial or empty value(not use a user defined initial value...like '0001/01/01').
Like String type can set String.init() or "" to it's value, so can use isEmpty() to determine it is empty, but how to do that with Date type variables?
It depends on what you are going to accomplish.
Naturally there is no empty date.
If the value of the date is irrelevant declare it with the current date
let date = Date()
If the date is supposed to be quite unspecified in the distant past or future there are
let date = Date.distantPast
let date = Date.distantFuture
If the date can be a specific date use the reference dates
let date = Date(timeIntervalSince1970: 0) // 1970/1/1
let date = Date(timeIntervalSinceReferenceDate: 0) // 2001/1/1
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