Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift3 Swift 3-无法转换日期类型的值?输入';NSDate&x27;胁迫_Swift3_Nsdate_Cllocation - Fatal编程技术网

Swift3 Swift 3-无法转换日期类型的值?输入';NSDate&x27;胁迫

Swift3 Swift 3-无法转换日期类型的值?输入';NSDate&x27;胁迫,swift3,nsdate,cllocation,Swift3,Nsdate,Cllocation,我有一个全局可选CLLocation变量,如下所示: var location : CLLocation? = nil 我想打开并将位置的时间戳转换为NSDate location?.timestamp as NSDate 我得到以下错误 无法转换日期类型的值?在强制中键入“NSDate” 我如何解决这个问题 PS:我是Swift 3的新手。您的位置属性是可选的,您正试图从中获取,以便获取可选的日期?实例,即您获取该错误的原因 在Swift 3中,使用Date代替NSDate,如果让或gua

我有一个全局
可选
CLLocation
变量,如下所示:

var location : CLLocation? = nil
我想打开并将位置的
时间戳
转换为
NSDate

location?.timestamp as NSDate
我得到以下错误

无法转换日期类型的值?在强制中键入“NSDate”

我如何解决这个问题


PS:我是Swift 3的新手。

您的
位置
属性是可选的,您正试图从中获取,以便获取可选的
日期?
实例,即您获取该错误的原因

在Swift 3中,使用
Date
代替
NSDate
,如果让
guard
打开包装,则使用

if let date = lastSavedLocation?.timestamp {
     print(date)
}