问题
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