rust_macios/user_notifications/
un_calendar_notification_trigger.rs1use objc::{msg_send, sel, sel_impl};
2use rust_macios_objective_c_runtime_proc_macros::interface_impl;
3
4use crate::{
5 foundation::{NSDate, NSDateComponents},
6 object,
7 objective_c_runtime::traits::FromId,
8 utils::to_optional,
9};
10
11use super::IUNNotificationTrigger;
12
13object! {
14 unsafe pub struct UNCalendarNotificationTrigger;
15}
16
17impl IUNNotificationTrigger for UNCalendarNotificationTrigger {}
18
19#[interface_impl(UNNotificationTrigger)]
20impl UNCalendarNotificationTrigger {
21 #[method]
26 pub fn trigger_with_date_matching_components_repeats(
27 date_components: NSDateComponents,
28 repeats: bool,
29 ) -> Self
30 where
31 Self: Sized + FromId,
32 {
33 unsafe {
34 Self::from_id(
35 msg_send![Self::m_class(), triggerWithDateMatchingComponents: date_components repeats: repeats],
36 )
37 }
38 }
39
40 #[method]
45 pub fn next_trigger_date(&self) -> Option<NSDate> {
46 unsafe { to_optional(msg_send![self.m_self(), nextTriggerDate]) }
47 }
48
49 #[property]
51 pub fn date_components(&self) -> NSDateComponents {
52 unsafe { NSDateComponents::from_id(msg_send![self.m_self(), dateComponents]) }
53 }
54}