objc2_cloud_kit/generated/
CKSyncEngineState.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// An object that tracks some state required for proper and efficient operation of `CKSyncEngine`.
12    ///
13    /// `CKSyncEngine` needs to track several things in order to properly sync.
14    /// For example, it needs to remember the last server change tokens for your database and zones.
15    /// It also needs to keep track of things like the last known user record ID and other various pieces of state.
16    ///
17    /// A lot of this state is hidden internally, but some of it you can control.
18    ///
19    /// ## Pending changes
20    ///
21    /// One of the main things you can control is the list of pending changes to send to the server.
22    /// You can control these by calling functions like ``addPendingDatabaseChanges:`` and  ``addPendingRecordZoneChanges:``.
23    /// When you add new pending changes, the sync engine will automatically schedule a task to sync with the server.
24    ///
25    /// ## State serialization
26    ///
27    /// `CKSyncEngine` will occasionally update its state in the background.
28    /// When it updates its state, your delegate will receive a ``CKSyncEngineStateUpdateEvent``.
29    ///
30    /// This event will contain a ``CKSyncEngineStateSerialization``, which you should persist locally.
31    /// The next time your process launches, you initialize your sync engine with the last state serialization you received.
32    ///
33    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginestate?language=objc)
34    #[unsafe(super(NSObject))]
35    #[derive(Debug, PartialEq, Eq, Hash)]
36    pub struct CKSyncEngineState;
37);
38
39unsafe impl Send for CKSyncEngineState {}
40
41unsafe impl Sync for CKSyncEngineState {}
42
43extern_conformance!(
44    unsafe impl NSObjectProtocol for CKSyncEngineState {}
45);
46
47impl CKSyncEngineState {
48    extern_methods!(
49        #[unsafe(method(init))]
50        #[unsafe(method_family = init)]
51        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
52
53        #[unsafe(method(new))]
54        #[unsafe(method_family = new)]
55        pub unsafe fn new() -> Retained<Self>;
56
57        /// A list of record changes that need to be sent to the server.
58        ///
59        /// `CKSyncEngine` provides the convenience of tracking your pending record zone changes.
60        /// When the user makes some changes that need to be sent to the server, you can track them in this list.
61        /// Then, you can use this list when creating your next `CKSyncEngineRecordZoneChangeBatch` in your `CKSyncEngineDelegate`.
62        ///
63        /// The sync engine will ensure consistency and deduplicate these pending changes under the hood.
64        /// For example, if you add a pending save for record A, then record B, then record A again, this will result in a list of `[saveRecordA, saveRecordB]`.
65        /// Similarly, if you add a pending save for record A, then add a pending delete for the same record A, this will result in a single pending change of `[deleteRecordA]`.
66        ///
67        /// The sync engine will manage this list while it sends changes to the server.
68        /// For example, when it successfully saves a record, it will remove that change from this list.
69        /// If it fails to send a change due to some retryable error (e.g. a network failure), it will keep that change in this list.
70        ///
71        /// If you'd prefer to track pending changes yourself, you can use `hasPendingUntrackedChanges` instead.
72        #[unsafe(method(pendingRecordZoneChanges))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn pendingRecordZoneChanges(
75            &self,
76        ) -> Retained<NSArray<CKSyncEnginePendingRecordZoneChange>>;
77
78        /// A list of database changes that need to be sent to the server, similar to `pendingRecordZoneChanges`.
79        #[unsafe(method(pendingDatabaseChanges))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn pendingDatabaseChanges(
82            &self,
83        ) -> Retained<NSArray<CKSyncEnginePendingDatabaseChange>>;
84
85        /// This represents whether or not you have pending changes to send to the server that aren't tracked in `pendingRecordZoneChanges`.
86        /// This is useful if you want to track pending changes in your own local database instead of the sync engine state.
87        ///
88        /// When this property is set, the sync engine will automatically schedule a sync.
89        /// When the sync task runs, it will ask your delegate for pending changes in `nextRecordZoneChangeBatch`.
90        #[unsafe(method(hasPendingUntrackedChanges))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn hasPendingUntrackedChanges(&self) -> bool;
93
94        /// Setter for [`hasPendingUntrackedChanges`][Self::hasPendingUntrackedChanges].
95        #[unsafe(method(setHasPendingUntrackedChanges:))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn setHasPendingUntrackedChanges(&self, has_pending_untracked_changes: bool);
98
99        #[cfg(feature = "CKRecordZoneID")]
100        /// The list of zone IDs that have new changes to fetch from the server.
101        /// `CKSyncEngine` keeps track of these zones and will update this list as it receives new information.
102        #[unsafe(method(zoneIDsWithUnfetchedServerChanges))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn zoneIDsWithUnfetchedServerChanges(&self)
105            -> Retained<NSArray<CKRecordZoneID>>;
106
107        /// Adds to the list of pending record zone changes.
108        ///
109        /// When you add a new pending change, the sync engine will automatically schedule a sync task.
110        ///
111        /// The sync engine will ensure consistency and deduplicate these changes under the hood.
112        #[unsafe(method(addPendingRecordZoneChanges:))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn addPendingRecordZoneChanges(
115            &self,
116            changes: &NSArray<CKSyncEnginePendingRecordZoneChange>,
117        );
118
119        /// Removes from the list of pending record zone changes.
120        #[unsafe(method(removePendingRecordZoneChanges:))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn removePendingRecordZoneChanges(
123            &self,
124            changes: &NSArray<CKSyncEnginePendingRecordZoneChange>,
125        );
126
127        /// Adds to the list of pending database changes.
128        ///
129        /// When you add a new pending change, the sync engine will automatically schedule a sync task.
130        ///
131        /// The sync engine will ensure consistency and deduplicate these changes under the hood.
132        #[unsafe(method(addPendingDatabaseChanges:))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn addPendingDatabaseChanges(
135            &self,
136            changes: &NSArray<CKSyncEnginePendingDatabaseChange>,
137        );
138
139        /// Removes from the list of pending database changes.
140        #[unsafe(method(removePendingDatabaseChanges:))]
141        #[unsafe(method_family = none)]
142        pub unsafe fn removePendingDatabaseChanges(
143            &self,
144            changes: &NSArray<CKSyncEnginePendingDatabaseChange>,
145        );
146    );
147}
148
149extern_class!(
150    /// A serialized representation of a ``CKSyncEngineState``.
151    ///
152    /// This will be passed to your delegate via ``CKSyncEngineStateUpdateEvent``.
153    /// You should use `NSSecureCoding` to persist this locally alongside your other data and use it the next time you initialize your sync engine.
154    ///
155    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginestateserialization?language=objc)
156    #[unsafe(super(NSObject))]
157    #[derive(Debug, PartialEq, Eq, Hash)]
158    pub struct CKSyncEngineStateSerialization;
159);
160
161unsafe impl Send for CKSyncEngineStateSerialization {}
162
163unsafe impl Sync for CKSyncEngineStateSerialization {}
164
165extern_conformance!(
166    unsafe impl NSCoding for CKSyncEngineStateSerialization {}
167);
168
169extern_conformance!(
170    unsafe impl NSObjectProtocol for CKSyncEngineStateSerialization {}
171);
172
173extern_conformance!(
174    unsafe impl NSSecureCoding for CKSyncEngineStateSerialization {}
175);
176
177impl CKSyncEngineStateSerialization {
178    extern_methods!(
179        #[unsafe(method(init))]
180        #[unsafe(method_family = init)]
181        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
182
183        #[unsafe(method(new))]
184        #[unsafe(method_family = new)]
185        pub unsafe fn new() -> Retained<Self>;
186    );
187}
188
189/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingrecordzonechangetype?language=objc)
190// NS_ENUM
191#[repr(transparent)]
192#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
193pub struct CKSyncEnginePendingRecordZoneChangeType(pub NSInteger);
194impl CKSyncEnginePendingRecordZoneChangeType {
195    #[doc(alias = "CKSyncEnginePendingRecordZoneChangeTypeSaveRecord")]
196    pub const SaveRecord: Self = Self(0);
197    #[doc(alias = "CKSyncEnginePendingRecordZoneChangeTypeDeleteRecord")]
198    pub const DeleteRecord: Self = Self(1);
199}
200
201unsafe impl Encode for CKSyncEnginePendingRecordZoneChangeType {
202    const ENCODING: Encoding = NSInteger::ENCODING;
203}
204
205unsafe impl RefEncode for CKSyncEnginePendingRecordZoneChangeType {
206    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
207}
208
209extern_class!(
210    /// A change in a record zone that needs to be sent to the server.
211    ///
212    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingrecordzonechange?language=objc)
213    #[unsafe(super(NSObject))]
214    #[derive(Debug, PartialEq, Eq, Hash)]
215    pub struct CKSyncEnginePendingRecordZoneChange;
216);
217
218unsafe impl Send for CKSyncEnginePendingRecordZoneChange {}
219
220unsafe impl Sync for CKSyncEnginePendingRecordZoneChange {}
221
222extern_conformance!(
223    unsafe impl NSObjectProtocol for CKSyncEnginePendingRecordZoneChange {}
224);
225
226impl CKSyncEnginePendingRecordZoneChange {
227    extern_methods!(
228        #[cfg(feature = "CKRecordID")]
229        #[unsafe(method(initWithRecordID:type:))]
230        #[unsafe(method_family = init)]
231        pub unsafe fn initWithRecordID_type(
232            this: Allocated<Self>,
233            record_id: &CKRecordID,
234            r#type: CKSyncEnginePendingRecordZoneChangeType,
235        ) -> Retained<Self>;
236
237        #[unsafe(method(init))]
238        #[unsafe(method_family = init)]
239        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
240
241        #[unsafe(method(new))]
242        #[unsafe(method_family = new)]
243        pub unsafe fn new() -> Retained<Self>;
244
245        #[cfg(feature = "CKRecordID")]
246        #[unsafe(method(recordID))]
247        #[unsafe(method_family = none)]
248        pub unsafe fn recordID(&self) -> Retained<CKRecordID>;
249
250        #[unsafe(method(type))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn r#type(&self) -> CKSyncEnginePendingRecordZoneChangeType;
253    );
254}
255
256/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingdatabasechangetype?language=objc)
257// NS_ENUM
258#[repr(transparent)]
259#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
260pub struct CKSyncEnginePendingDatabaseChangeType(pub NSInteger);
261impl CKSyncEnginePendingDatabaseChangeType {
262    #[doc(alias = "CKSyncEnginePendingDatabaseChangeTypeSaveZone")]
263    pub const SaveZone: Self = Self(0);
264    #[doc(alias = "CKSyncEnginePendingDatabaseChangeTypeDeleteZone")]
265    pub const DeleteZone: Self = Self(1);
266}
267
268unsafe impl Encode for CKSyncEnginePendingDatabaseChangeType {
269    const ENCODING: Encoding = NSInteger::ENCODING;
270}
271
272unsafe impl RefEncode for CKSyncEnginePendingDatabaseChangeType {
273    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
274}
275
276extern_class!(
277    /// A change in a database that needs to be sent to the server.
278    ///
279    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingdatabasechange?language=objc)
280    #[unsafe(super(NSObject))]
281    #[derive(Debug, PartialEq, Eq, Hash)]
282    pub struct CKSyncEnginePendingDatabaseChange;
283);
284
285unsafe impl Send for CKSyncEnginePendingDatabaseChange {}
286
287unsafe impl Sync for CKSyncEnginePendingDatabaseChange {}
288
289extern_conformance!(
290    unsafe impl NSObjectProtocol for CKSyncEnginePendingDatabaseChange {}
291);
292
293impl CKSyncEnginePendingDatabaseChange {
294    extern_methods!(
295        #[unsafe(method(init))]
296        #[unsafe(method_family = init)]
297        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
298
299        #[unsafe(method(new))]
300        #[unsafe(method_family = new)]
301        pub unsafe fn new() -> Retained<Self>;
302
303        #[cfg(feature = "CKRecordZoneID")]
304        #[unsafe(method(zoneID))]
305        #[unsafe(method_family = none)]
306        pub unsafe fn zoneID(&self) -> Retained<CKRecordZoneID>;
307
308        #[unsafe(method(type))]
309        #[unsafe(method_family = none)]
310        pub unsafe fn r#type(&self) -> CKSyncEnginePendingDatabaseChangeType;
311    );
312}
313
314extern_class!(
315    /// A zone save that needs to be sent to the server.
316    ///
317    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingzonesave?language=objc)
318    #[unsafe(super(CKSyncEnginePendingDatabaseChange, NSObject))]
319    #[derive(Debug, PartialEq, Eq, Hash)]
320    pub struct CKSyncEnginePendingZoneSave;
321);
322
323unsafe impl Send for CKSyncEnginePendingZoneSave {}
324
325unsafe impl Sync for CKSyncEnginePendingZoneSave {}
326
327extern_conformance!(
328    unsafe impl NSObjectProtocol for CKSyncEnginePendingZoneSave {}
329);
330
331impl CKSyncEnginePendingZoneSave {
332    extern_methods!(
333        #[cfg(feature = "CKRecordZone")]
334        #[unsafe(method(initWithZone:))]
335        #[unsafe(method_family = init)]
336        pub unsafe fn initWithZone(this: Allocated<Self>, zone: &CKRecordZone) -> Retained<Self>;
337
338        #[cfg(feature = "CKRecordZone")]
339        #[unsafe(method(zone))]
340        #[unsafe(method_family = none)]
341        pub unsafe fn zone(&self) -> Retained<CKRecordZone>;
342    );
343}
344
345/// Methods declared on superclass `CKSyncEnginePendingDatabaseChange`.
346impl CKSyncEnginePendingZoneSave {
347    extern_methods!(
348        #[unsafe(method(init))]
349        #[unsafe(method_family = init)]
350        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
351
352        #[unsafe(method(new))]
353        #[unsafe(method_family = new)]
354        pub unsafe fn new() -> Retained<Self>;
355    );
356}
357
358extern_class!(
359    /// A zone delete that needs to be sent to the server.
360    ///
361    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingzonedelete?language=objc)
362    #[unsafe(super(CKSyncEnginePendingDatabaseChange, NSObject))]
363    #[derive(Debug, PartialEq, Eq, Hash)]
364    pub struct CKSyncEnginePendingZoneDelete;
365);
366
367unsafe impl Send for CKSyncEnginePendingZoneDelete {}
368
369unsafe impl Sync for CKSyncEnginePendingZoneDelete {}
370
371extern_conformance!(
372    unsafe impl NSObjectProtocol for CKSyncEnginePendingZoneDelete {}
373);
374
375impl CKSyncEnginePendingZoneDelete {
376    extern_methods!(
377        #[cfg(feature = "CKRecordZoneID")]
378        #[unsafe(method(initWithZoneID:))]
379        #[unsafe(method_family = init)]
380        pub unsafe fn initWithZoneID(
381            this: Allocated<Self>,
382            zone_id: &CKRecordZoneID,
383        ) -> Retained<Self>;
384    );
385}
386
387/// Methods declared on superclass `CKSyncEnginePendingDatabaseChange`.
388impl CKSyncEnginePendingZoneDelete {
389    extern_methods!(
390        #[unsafe(method(init))]
391        #[unsafe(method_family = init)]
392        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
393
394        #[unsafe(method(new))]
395        #[unsafe(method_family = new)]
396        pub unsafe fn new() -> Retained<Self>;
397    );
398}