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
location
property is optional and you are trying to gettimestamp
from it so that you are getting optionalDate?
instance i.e the reason you are getting that error.In Swift 3 use
Date
instead ofNSDate
and useif let
orguard
to unwrapped optional.