0
我需要安排通知。如果從具有dateFromData時間組件的當前日期日期組件創建的日期早於當前日期,那麼我想將其更改爲第二天。這是我到目前爲止。無論我如何設置,日期比較劑量都不起作用。它要麼總是改變它,要麼永遠不會改變它。Swift NSDate比較
var dateComps = calendar.components(NSCalendarUnit.YearCalendarUnit | NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit | NSCalendarUnit.HourCalendarUnit | NSCalendarUnit.MinuteCalendarUnit, fromDate: NSDate())
dateComps.hour = calendar.component(NSCalendarUnit.HourCalendarUnit, fromDate: dateFromData)
dateComps.minute = calendar.component(NSCalendarUnit.MinuteCalendarUnit, fromDate: dateFromData)
if fireDate.compare(NSDate()) == NSComparisonResult.OrderedDescending {
//change day to next day
dateComps.day += 1
println("Change day")
}else{
println("Do not change day")
}
let notifactionOfAmountOfWork = UILocalNotification()
notifactionOfAmountOfWork.category = "normalNotifactionCatagory"
notifactionOfAmountOfWork.fireDate = calendar.dateFromComponents(dateComps)
謝謝,問題是,dateFromData是從時間日期選擇器視圖。 – 2015-02-10 03:31:15