title: Scheduling notification with Swift 3 for an array of dates
body: <p>I have an array containing my dates. I want to schedule notifications for those days at 6.30am.</p>
  
  <p>I followed the <a href="http://www.appcoda.com/ios10-user-notifications-guide/" rel="nofollow noreferrer">appcoda tutorial</a> which helps scheduling the notification upon input from a datepicker which is great, but I am a bit uncertain on how to call my function to schedule the notification for only the given days.</p>
  
  <p><strong>So my question is how and where to call the function?</strong></p>
  
  <ul>
  <li>the days are consecutive days</li>
  <li>can I give the function a start date and repeat it with the number of items in the array?</li>
  </ul>
  
  <p>Below is my function:</p>
  
  <pre><code>    func scheduleNotification(at date: Date) {
          let calendar = Calendar(identifier: .gregorian)
          let components = calendar.dateComponents(in: .current, from: date)
          let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: 6, minute: 30)
          let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: false)
  
          let content = UNMutableNotificationContent()
          content.title = "Advent Calendar"
          content.body = "Just a reminder to open your present!"
          content.sound = UNNotificationSound.default()
  
          let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)
   UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
          UNUserNotificationCenter.current().add(request) {(error) in
              if let error = error {
                  print("Uh oh! We had an error: \(error)")
              }
          }
      }
  </code></pre>