使用未声明的类型 'Date' Xcode 9 Swift 4

use of undeclared type 'Date' Xcode 9 Swift 4

这是我在 xcode 9 playground

中的代码
class Tutorial: Codable {
    let title: String
    let author: String
    let editor: String
    let type: String
    let publishDate: Date

    init(title: String, author: String, editor: String, type: String, publishDate: Date) {
        self.title = title
        self.author = author
        self.editor = editor
        self.type = type
        self.publishDate = publishDate
    }
}

它显示未声明类型的错误使用 'Date'

Date 结构是 Foundation 框架的一部分。

在你的 playground 开头添加 import Foundation

作为一般规则,您应该始终至少导入 Foundation,因为我们日常使用的许多类型都是 Foundation 的一部分。您也可以仅导入 UIKit(因为 UIKit 会自动导入 Foundation)。