0

I am trying to get the dates for the whole week. I can currently get the current date, but I want to add 6 days to that so I can get a list of the whole week. How would I do that? Any help is appreciated!

let now = NSDate()
override func viewDidLoad() {
    super.viewDidLoad()
  print("Now \(now)") //prints current date
}
stackerleet
  • 518
  • 1
  • 5
  • 16
  • 1
    see this link it helps you http://stackoverflow.com/questions/33397101/how-to-get-mondays-date-of-the-current-week-in-swift – Anbu.Karthik Jan 30 '16 at 06:37

1 Answers1

0

A quick and easy way of doing it:

if let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) {
  var thisWeek = [NSDate]()
  for i in 0...6 {
    if let nextDay = calendar.dateByAddingUnit(NSCalendarUnit.Day , value: i, toDate: NSDate(), options: .MatchStrictly) {
      thisWeek.append(nextDay)
    }
  }
}
  • @LeoDabus Why won't it work? The first day will be today + 0 days. Next is +1 days... –  Jan 30 '16 at 07:07
  • 1
    @LeoDabus Yeah that's just creating the array. I originally manually added the first day and did 1...6 but I simplified it. –  Jan 30 '16 at 07:11