我想问一下如何从字符串中设置提醒,并在确切时间之前10分钟以及之后UI从时间a更改为时间b时给您通知。
let a = "04:12"
let b = "11:38"
let c = "15:00"
let d = "18:03"
let e ="18:59"
我正在像这样设置计时器,但我不知道从这里应该去哪里。这是我的代码:
extension Date {
var hour: Int { return Calendar.current.component(.hour, from: self)}
var minute: Int { return Calendar.current.component(.minute, from: self)}
}
@objc func scheduleTime() {
timer = Timer(fireAt: Calendar.current.nextDate(after: Date(), matching: DateComponents(hour: 0...23 ~= Date().hour ? 23 : 0), matchingPolicy: .nextTime)!, interval: 0, target: self, selector: #selector(updateUI), userInfo: nil, repeats: false)
RunLoop.main.add(timer, forMode: .common)
}