结构中的日期对象....SWIFT



我正在使用Swift创建一个iOS应用程序;它创建并管理用户任务。我在struct对象中有每个任务,但我不知道如何初始化date对象。

struct DailyTask: Identifiable, Codable {
let id: UUID
var title: String
var taskDescription: String
var dueDate: **HERE?**
var lengthInDays: Int
var theme: Theme

init(id: UUID = UUID(), title: String, taskDescription: String, dueDate: String, lengthInDays: Int, theme: Theme) {
self.id = id
self.title = title
self.taskDescription = taskDescription
self.dueDate = dueDate
self.lengthInDays = lengthInDays
self.theme = theme
}
}
extension DailyTask {
struct Data {
var title: String = ""
var taskDescription: String = ""
var dueDate: **HERE??**
var lengthInDays: Int = 5
var theme: Theme = .seafoam
}
extension DailyTask {
static let sampleData: [DailyTask] =
[
DailyTask(title: "Homework #15 - Reading", taskDescription: "Read first three chapters of textbook. Read first three chapters of", dueDate: **WHAT CLEAR** , lengthInDays: 2, theme: .magenta),
]
}

为什么不能将到期日作为Date

struct DailyTask: Identifiable, Codable {
let id: UUID
var title: String
var taskDescription: String
var dueDate: Date?
var lengthInDays: Int
var theme: Theme
init(id: UUID = UUID(), title: String, taskDescription: String, dueDate: Date?, lengthInDays: Int, theme: Theme) {
self.id = id
self.title = title
self.taskDescription = taskDescription
self.dueDate = dueDate
self.lengthInDays = lengthInDays
self.theme = theme
}

最新更新