It seems that I can\'t subtract 7 days from the current date. This is how i am doing it:
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:N
Here is another way the original poster can get one week ago if he already has a date variable (updates/mutates itself).
extension Date {
mutating func changeDays(by days: Int) {
self = Calendar.current.date(byAdding: .day, value: days, to: self)!
}
}
var myDate = Date() // Jan 08, 2019
myDate.changeDays(by: 7) // Jan 15, 2019
myDate.changeDays(by: 7) // Jan 22, 2019
myDate.changeDays(by: -1) // Jan 21, 2019
// Iterate through one week
for i in 1...7 {
myDate.changeDays(by: i)
// Do something
}