I am trying to write an extension where NSDate can be changed to the another date. I want to make an extension which will modify self.
I've check different methods but cannot find how to modify self I am trying something like that but it doesn't work.
extension NSDate {
func changeDate(unitType: NSCalendarUnit, number: Int, date: NSDate) {
self.laterDate(NSCalendar.currentCalendar().dateByAddingUnit(
.Day,
value: number,
toDate: date,
options: []
)!)
}
}
In another file I am doing something like that:
let date = NSDate()
// set date to tomorrow
date.changeDate(.Day, number: 1, date: date)
What is the solution?