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

Kis*_*har 2 ios swift swift-playground

这是我在xcode 9游乐场的代码

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
    }
}
Run Code Online (Sandbox Code Playgroud)

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

dea*_*eef 9

Date结构是部分Foundation框架.

import Foundation在游乐场的开头添加.

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