使用未声明的类型 'Date' Xcode 9 Swift 4 [英] use of undeclared type 'Date' Xcode 9 Swift 4

查看:22
本文介绍了使用未声明的类型 'Date' Xcode 9 Swift 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在 xcode 9 playground 中的代码

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'

推荐答案

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

The Date struct is part of the Foundation framework.

在您的 Playground 开头添加 import Foundation.

Add import Foundation at the beginning of your playground.

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

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).

这篇关于使用未声明的类型 'Date' Xcode 9 Swift 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆