title: Convert Date to DateComponents in function to schedule local notification in Swift 3
body: <p>I'm attempting to setup a function that takes in an integer and schedules a local notification n days in the future. I'm getting an error that I can't convert type Date to DateComponents. I haven't been able to figure out how to convert it. I found a few other similar questions <a href="https://stackoverflow.com/questions/15252316/schedule-local-notification-after-app-was-closed-for-7-days">here</a> and <a href="https://stackoverflow.com/questions/38669845/how-to-set-a-weekly-local-notification-in-swift">here</a>, but I haven't been able to adapt those answers to work on Swift 3.</p>
  
  <p>How can I convert Date to DateComponents? Is there a better way to schedule the notification?</p>
  
  <p>Thanks in advance for the help :)</p>
  
  <p>The line with the error, "Cannot convert value of type 'Date?' to expected argument type 'DateComponents'":</p>
  
  <pre><code>let trigger = UNCalendarNotificationTrigger(dateMatching: fireDateOfNotification, repeats: false)
  </code></pre>
  
  <p>Full function:</p>
  
  <pre><code>func scheduleNotification(day:Int) {    
      let date = Date()
      let calendar = Calendar.current
      var components = calendar.dateComponents([.day, .month, .year], from: date as Date)
      let tempDate = calendar.date(from: components)
      var comps = DateComponents()
  
      //set future day variable
      comps.day = day
  
      //set date to fire alert
      let fireDateOfNotification = calendar.date(byAdding: comps as DateComponents, to: tempDate!)
  
      let trigger = UNCalendarNotificationTrigger(dateMatching: fireDateOfNotification, repeats: false) //THIS LINE CAUSES ERROR
  
      let content = UNMutableNotificationContent()
      content.title = "New Alert Title"
      content.body = "Body of alert"
      content.sound = UNNotificationSound.default()
  
      let request = UNNotificationRequest(identifier: "alertNotification", content: content, trigger: trigger)
  
      UNUserNotificationCenter.current().add(request) {(error) in
          if let error = error {
              print("Uh oh! We had an error: \(error)")
          }
      }
   }
  </code></pre>