use of undeclared type 'Date' Xcode 9 Swift 4

ぐ巨炮叔叔 提交于 2019-12-11 02:29:24

问题


This is my code in 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
    }
}

its showing error use of undeclared type 'Date'


回答1:


The Date struct is part of the Foundation framework.

Add import Foundation at the beginning of your playground.

As a general rule, you should always import at least Foundation because many of the everyday types we use are part of Foundation. You can also import only UIKit (because UIKit automatically imports Foundation).



来源:https://stackoverflow.com/questions/44944220/use-of-undeclared-type-date-xcode-9-swift-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!