title: What is the most effective way to iterate over a date range in Swift?
body: <p>I am building a Swift habit-building application.  At a certain point, a user selects the duration (in days) of the habit they'd like to create.  The user can also select which days of the week they'd like to practice it (sunday, monday, tuesday, etc.).  The start date is the day they create the habit.</p>
  
  <p>I currently have the start date and end date (based on number of days selected by user).  Within that date range, however, I need to extract dates for the specific days the user has chosen.</p>
  
  <p>My thinking is that for every weekday value 'x' within time interval (startDate, endDate), return Calendar date.  However, I have tried creating a DateInterval, and I am unable to iterate over it because it does not conform to protocol 'Sequence'.  </p>
  
  <p>Is there an efficient way of iterating over this date range and extracting these other dates?  Is there a better way that I'm not yet thinking of?</p>
  
  <p>Here's my current date starter code below:  </p>
  
  <pre><code>var date = Date()
  var duration = 10
  let calendar = Calendar.current
  
  let dateEnding = Calendar.current.date(byAdding: .day, value: duration, to: date as Date)!
  
  //Returns a number representing day of the week.  i.e. 1 = Sunday
  let weekDay = calendar.component(.weekday, from: date)
  
  
  //Initializing a time interval, based on user selected duration and start date
  let timeInterval = DateInterval.init(start: date, end: dateEnding)
  </code></pre>
  
  <p>Thanks for your help...</p>