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

时间:2017-07-06 08:58:01

标签: ios swift swift-playground

这是我在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
    }
}

显示错误使用未声明类型“日期”

1 个答案:

答案 0 :(得分:8)

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

在游乐场的开头添加import Foundation

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