Is there a good way to check if a NSDate is between now and x days away from now?
I mean without filtering the month-day and doing stuff on it manually.
I use swift to develop and am very new in iOS developing.
Is there a good way to check if a NSDate is between now and x days away from now?
I mean without filtering the month-day and doing stuff on it manually.
I use swift to develop and am very new in iOS developing.
If you know how to compare two dates you can use dateByAddingUnit to find out the date xDays from today as follow:
edit/update: Swift 3.x - Swift 4
extension Date {
func adding(days: Int) -> Date {
return Calendar.current.date(byAdding: .day, value: days, to: self)!
}
}
let fiveDaysFromToday = Date().adding(days: 5) // "Jun 19, 2017 at 5:25 PM"