title: Get weekdays within a month
body: <p>I'm trying to get the dates within a given month.</p>
  
  <p>My plan is to </p>
  
  <ol>
  <li>Get the start and the end dates of a given month,.</li>
  <li>Get all the dates that fall within that range.</li>
  <li>Iterate through them and eliminate dates that fall within a weekend using the <a href="https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/index.html#//apple_ref/occ/instm/NSCalendar/isDateInWeekend:" rel="nofollow"><code>isDateInWeekend</code></a> method.</li>
  </ol>
  
  <p>The remaining dates are the weekdays.</p>
  
  <p>So I created two <code>NSDate</code> extension methods to get the start and the end dates of the month.</p>
  
  <pre><code>extension NSDate {
      var startOfMonth: NSDate {
          let calendar = NSCalendar.currentCalendar()
          let components = calendar.components([.Year, .Month], fromDate: self)
          return calendar.dateFromComponents(components)!
      }
  
      var endOfMonth: NSDate {
          let calendar = NSCalendar.currentCalendar()
          let components = NSDateComponents()
          components.month = 1
          return (calendar.dateByAddingComponents(components, toDate: self.startOfMonth, options: NSCalendarOptions())?.dateByAddingTimeInterval(-1))!
      }
  }
  </code></pre>
  
  <p>Now I'm stuck at step #2. I can't find a way to get a range of dates given a start and an end date.</p>
  
  <p>Is there a way to do this?</p>