I have a global optional CLLocation variable as follows:
var location : CLLocation? = nil
I want to unwrap and convert the timestamp of the location to NSDate.
location?.timestamp as NSDate
I get the following error
Cannot convert value of type Date? to type 'NSDate' in coercion.
How do I resolve this?
PS: I am a newbie to Swift 3.
Your
locationproperty is optional and you are trying to gettimestampfrom it so that you are getting optionalDate?instance i.e the reason you are getting that error.In Swift 3 use
Dateinstead ofNSDateand useif letorguardto unwrapped optional.