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