objc2_foundation/generated/
NSTimer.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8
9use crate::*;
10
11extern_class!(
12    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nstimer?language=objc)
13    #[unsafe(super(NSObject))]
14    #[derive(Debug, PartialEq, Eq, Hash)]
15    pub struct NSTimer;
16);
17
18#[cfg(feature = "objc2-core-foundation")]
19impl AsRef<NSTimer> for CFRunLoopTimer {
20    #[inline]
21    fn as_ref(&self) -> &NSTimer {
22        unsafe { &*((self as *const Self).cast()) }
23    }
24}
25
26#[cfg(feature = "objc2-core-foundation")]
27impl AsRef<CFRunLoopTimer> for NSTimer {
28    #[inline]
29    fn as_ref(&self) -> &CFRunLoopTimer {
30        unsafe { &*((self as *const Self).cast()) }
31    }
32}
33
34extern_conformance!(
35    unsafe impl NSObjectProtocol for NSTimer {}
36);
37
38impl NSTimer {
39    extern_methods!(
40        #[cfg(all(feature = "NSDate", feature = "NSInvocation"))]
41        #[unsafe(method(timerWithTimeInterval:invocation:repeats:))]
42        #[unsafe(method_family = none)]
43        pub unsafe fn timerWithTimeInterval_invocation_repeats(
44            ti: NSTimeInterval,
45            invocation: &NSInvocation,
46            yes_or_no: bool,
47        ) -> Retained<NSTimer>;
48
49        #[cfg(all(feature = "NSDate", feature = "NSInvocation"))]
50        #[unsafe(method(scheduledTimerWithTimeInterval:invocation:repeats:))]
51        #[unsafe(method_family = none)]
52        pub unsafe fn scheduledTimerWithTimeInterval_invocation_repeats(
53            ti: NSTimeInterval,
54            invocation: &NSInvocation,
55            yes_or_no: bool,
56        ) -> Retained<NSTimer>;
57
58        #[cfg(feature = "NSDate")]
59        /// # Safety
60        ///
61        /// - `a_target` should be of the correct type.
62        /// - `a_selector` must be a valid selector.
63        /// - `user_info` should be of the correct type.
64        #[unsafe(method(timerWithTimeInterval:target:selector:userInfo:repeats:))]
65        #[unsafe(method_family = none)]
66        pub unsafe fn timerWithTimeInterval_target_selector_userInfo_repeats(
67            ti: NSTimeInterval,
68            a_target: &AnyObject,
69            a_selector: Sel,
70            user_info: Option<&AnyObject>,
71            yes_or_no: bool,
72        ) -> Retained<NSTimer>;
73
74        #[cfg(feature = "NSDate")]
75        /// # Safety
76        ///
77        /// - `a_target` should be of the correct type.
78        /// - `a_selector` must be a valid selector.
79        /// - `user_info` should be of the correct type.
80        #[unsafe(method(scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:))]
81        #[unsafe(method_family = none)]
82        pub unsafe fn scheduledTimerWithTimeInterval_target_selector_userInfo_repeats(
83            ti: NSTimeInterval,
84            a_target: &AnyObject,
85            a_selector: Sel,
86            user_info: Option<&AnyObject>,
87            yes_or_no: bool,
88        ) -> Retained<NSTimer>;
89
90        #[cfg(all(feature = "NSDate", feature = "block2"))]
91        /// Creates and returns a new NSTimer object initialized with the specified block object. This timer needs to be scheduled on a run loop (via -[NSRunLoop addTimer:]) before it will fire.
92        /// - parameter:  timeInterval  The number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead
93        /// - parameter:  repeats  If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
94        /// - parameter:  block  The execution body of the timer; the timer itself is passed as the parameter to this block when executed to aid in avoiding cyclical references
95        ///
96        /// # Safety
97        ///
98        /// `block` block must be sendable.
99        #[unsafe(method(timerWithTimeInterval:repeats:block:))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn timerWithTimeInterval_repeats_block(
102            interval: NSTimeInterval,
103            repeats: bool,
104            block: &block2::DynBlock<dyn Fn(NonNull<NSTimer>)>,
105        ) -> Retained<NSTimer>;
106
107        #[cfg(all(feature = "NSDate", feature = "block2"))]
108        /// Creates and returns a new NSTimer object initialized with the specified block object and schedules it on the current run loop in the default mode.
109        /// - parameter:  ti    The number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead
110        /// - parameter:  repeats  If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
111        /// - parameter:  block  The execution body of the timer; the timer itself is passed as the parameter to this block when executed to aid in avoiding cyclical references
112        ///
113        /// # Safety
114        ///
115        /// `block` block must be sendable.
116        #[unsafe(method(scheduledTimerWithTimeInterval:repeats:block:))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn scheduledTimerWithTimeInterval_repeats_block(
119            interval: NSTimeInterval,
120            repeats: bool,
121            block: &block2::DynBlock<dyn Fn(NonNull<NSTimer>)>,
122        ) -> Retained<NSTimer>;
123
124        #[cfg(all(feature = "NSDate", feature = "block2"))]
125        /// Initializes a new NSTimer object using the block as the main body of execution for the timer. This timer needs to be scheduled on a run loop (via -[NSRunLoop addTimer:]) before it will fire.
126        /// - parameter:  fireDate   The time at which the timer should first fire.
127        /// - parameter:  interval  The number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead
128        /// - parameter:  repeats  If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
129        /// - parameter:  block  The execution body of the timer; the timer itself is passed as the parameter to this block when executed to aid in avoiding cyclical references
130        ///
131        /// # Safety
132        ///
133        /// `block` block must be sendable.
134        #[unsafe(method(initWithFireDate:interval:repeats:block:))]
135        #[unsafe(method_family = init)]
136        pub unsafe fn initWithFireDate_interval_repeats_block(
137            this: Allocated<Self>,
138            date: &NSDate,
139            interval: NSTimeInterval,
140            repeats: bool,
141            block: &block2::DynBlock<dyn Fn(NonNull<NSTimer>)>,
142        ) -> Retained<Self>;
143
144        #[cfg(feature = "NSDate")]
145        /// # Safety
146        ///
147        /// - `t` should be of the correct type.
148        /// - `s` must be a valid selector.
149        /// - `ui` should be of the correct type.
150        #[unsafe(method(initWithFireDate:interval:target:selector:userInfo:repeats:))]
151        #[unsafe(method_family = init)]
152        pub unsafe fn initWithFireDate_interval_target_selector_userInfo_repeats(
153            this: Allocated<Self>,
154            date: &NSDate,
155            ti: NSTimeInterval,
156            t: &AnyObject,
157            s: Sel,
158            ui: Option<&AnyObject>,
159            rep: bool,
160        ) -> Retained<Self>;
161
162        #[unsafe(method(fire))]
163        #[unsafe(method_family = none)]
164        pub fn fire(&self);
165
166        #[cfg(feature = "NSDate")]
167        #[unsafe(method(fireDate))]
168        #[unsafe(method_family = none)]
169        pub fn fireDate(&self) -> Retained<NSDate>;
170
171        #[cfg(feature = "NSDate")]
172        /// Setter for [`fireDate`][Self::fireDate].
173        ///
174        /// This is [copied][crate::NSCopying::copy] when set.
175        #[unsafe(method(setFireDate:))]
176        #[unsafe(method_family = none)]
177        pub fn setFireDate(&self, fire_date: &NSDate);
178
179        #[cfg(feature = "NSDate")]
180        #[unsafe(method(timeInterval))]
181        #[unsafe(method_family = none)]
182        pub fn timeInterval(&self) -> NSTimeInterval;
183
184        #[cfg(feature = "NSDate")]
185        #[unsafe(method(tolerance))]
186        #[unsafe(method_family = none)]
187        pub fn tolerance(&self) -> NSTimeInterval;
188
189        #[cfg(feature = "NSDate")]
190        /// Setter for [`tolerance`][Self::tolerance].
191        #[unsafe(method(setTolerance:))]
192        #[unsafe(method_family = none)]
193        pub fn setTolerance(&self, tolerance: NSTimeInterval);
194
195        #[unsafe(method(invalidate))]
196        #[unsafe(method_family = none)]
197        pub fn invalidate(&self);
198
199        #[unsafe(method(isValid))]
200        #[unsafe(method_family = none)]
201        pub fn isValid(&self) -> bool;
202
203        #[unsafe(method(userInfo))]
204        #[unsafe(method_family = none)]
205        pub fn userInfo(&self) -> Option<Retained<AnyObject>>;
206    );
207}
208
209/// Methods declared on superclass `NSObject`.
210impl NSTimer {
211    extern_methods!(
212        #[unsafe(method(init))]
213        #[unsafe(method_family = init)]
214        pub fn init(this: Allocated<Self>) -> Retained<Self>;
215
216        #[unsafe(method(new))]
217        #[unsafe(method_family = new)]
218        pub fn new() -> Retained<Self>;
219    );
220}
221
222impl DefaultRetained for NSTimer {
223    #[inline]
224    fn default_retained() -> Retained<Self> {
225        Self::new()
226    }
227}