让future = sender.date-FUTURE是什么类型?

时间:2019-05-24 13:19:00

标签: ios swift date

有人可以告诉我下面这段代码中的“未来”是什么类型吗?

@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."
}

1 个答案:

答案 0 :(得分:0)

如功能签名所示,sender的类型为UIDatePicker,而UIDatePicker的{​​{3}}的类型为date的属性为{{ 1}},因此Date的类型为future

如果不确定变量的类型,则应查阅文档(内置于Xcode或在线)或使用Option +单击Xco​​de中的变量以显示其类型。

相关问题