有人可以告诉我下面这段代码中的“未来”是什么类型吗?
@IBAction func datePickerChanged(_ sender: UIDatePicker) {
let future = sender.date
//Use midnight today as the starting date
guard let today = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: Date()) else { return }
//Calculate the number of days between today and the =user's chosen day.
let difference = Calendar.current.dateComponents([.day], from: today, to: future)
guard let days = difference.day else { return }
let ess = days > 1 ? "s" : ""
countLabel.text = "That date is \(days) day\(ess) away."
}
答案 0 :(得分:0)
如功能签名所示,sender
的类型为UIDatePicker
,而UIDatePicker
的{{3}}的类型为date
的属性为{{ 1}},因此Date
的类型为future
。
如果不确定变量的类型,则应查阅文档(内置于Xcode或在线)或使用Option +单击Xcode中的变量以显示其类型。