title: Swift: Repeating Notification every day on selected Hour
body: <p>I have created a way for the user to select a time that they would like to receive daily notifications. I'm able to get the notification to fire once at the selected time but it doesn't repeat daily. Can anyone see where I may have gone wrong?</p>
  <pre><code>'''
   @IBAction func scheduleDate(_ sender: UIButton)
  {
      let quotes = Bundle.main.decode([Quote].self, from: &quot;quotes.json&quot;)
      let quote = quotes.randomElement()
      let message = quote?.shareMessage
      
      notificationCenter.getNotificationSettings {  (settings) in
          DispatchQueue.main.async {
              
      let date = self.datePicker.date
             
  
      if(settings.authorizationStatus == .authorized)
      {
          //self.notificationCenter.removeAllPendingNotificationRequests()
          //self.notificationCenter.removeAllDeliveredNotifications()
          //center.removeAllPendingNotificationRequests()
          let shuffled = self.quotes.shuffled()
          
  
          for i in 1...1 {
            
              let content = UNMutableNotificationContent()
              content.title = &quot;Your Notification&quot;
              content.subtitle = &quot;Your Scheduled Quote&quot;
              content.body = message ?? &quot;Love Is Love&quot; //shuffled?[i]
              content.threadIdentifier = &quot;Get Notified&quot;
              
              
          let dateComp = Calendar.current.dateComponents([.day, .hour, .minute], from: date)//.byAdding(days: i))
          let trigger = UNCalendarNotificationTrigger(dateMatching: dateComp, repeats: true)
          let requestIdentifier = &quot;UserSetQuote&quot;
          let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger)
          self.notificationCenter.add(request) { (error) in
              if(error != nil)
              {
                  print(&quot;Error &quot; + error.debugDescription)
                  return
              }
          }
          }
          let ac = UIAlertController(title: &quot;Notification Scheduled&quot;,
                                     message: &quot;At &quot; + self.formattedDate(date: date), preferredStyle: .alert)
          
         
  
          ac.addAction(UIAlertAction(title: &quot;OK&quot;, style: .default, handler: { (_) in }))
          self.present(ac, animated: true)
          self.scheduleTime2.text = &quot;Your quote is scheduled for &quot; + self.formattedDate(date: date)
          
      }
          else
          {
              let ac = UIAlertController(title: &quot;Enable Notifcations?&quot;,
                                         message: &quot;To use this feature you must enable notications in settings&quot; , preferredStyle: .alert)
              let goToSettings = UIAlertAction(title: &quot;Settings&quot;, style: .default) { (_) in
              guard let settingsURL = URL(string: UIApplication.openSettingsURLString)
                  else
                  {
                  return
                  }
                  
                  if(UIApplication.shared.canOpenURL(settingsURL))
                  {
                      
                      UIApplication.shared.open(settingsURL) { (_) in }
                  }
              }
              ac.addAction(goToSettings)
              ac.addAction(UIAlertAction(title: &quot;Cancel&quot;, style: .default, handler: { (_) in }))
              self.present(ac, animated: true)
          }
  }
  }
     
     
  </code></pre>
  <p>}
  Here is my code to format my hour using a date picker(only using hour and minutes)</p>
  <pre><code>func formattedDate(date: Date) -&gt; String
  {
      let formatter = DateFormatter()
      formatter.dateFormat = &quot;h:mm a&quot;
      return formatter.string(from: date)
  }
  </code></pre>
  <p>}
  ≈</p>
  <p>}
  ''''</p>