-5

This code would create a notification trigger that repeats every day at 10am, right?

var dateComponents = DateComponents()
dateComponents.hour = 10
dateComponents.minute = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)

Would changing the 2nd line to dateComponents.hour = 22 set it for 10pm?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
RanLearns
  • 4,086
  • 5
  • 44
  • 81

1 Answers1

1

Yes. DateComponents uses 24 hours format by default.

If you want to know more about it, I would suggest this great article.

shbedev
  • 1,875
  • 17
  • 28
  • 3
    Note that hour component it is not limited to 24 hours. You can pass any amount of hours. try `DateComponents(calendar: .current, year: 2019, day: 1, hour: 40).date!` it will result in `"Jan 2, 2019 at 4:00 PM"` – Leo Dabus Nov 13 '19 at 15:12
  • @LeoDabus that is why I asked the question. I know you can set a one time notification 40 hours or 256 hours in the future, but for setting a repeating notification at an exact time (i.e. 10am every day or 10pm every day) I wasn't sure. I'm more used to using timeIntervalSinceNow, so typically I've used an integer to represent time added to the current time, not for setting the notification to an exact hour. – RanLearns Nov 13 '19 at 16:08