objc2_cloud_kit/generated/
CKSyncEngine.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    /// `CKSyncEngine` encapsulates the logic of syncing data with a CloudKit database.
12    ///
13    /// Syncing with CloudKit involves many moving pieces.
14    /// Apps need to schedule syncs, create and batch operations, subscribe to database changes,
15    /// listen for push notifications, store sync state, handle a multitude of errors, and more.
16    /// `CKSyncEngine` is designed to encapsulate this logic in a higher-level API.
17    ///
18    /// # Start Your Sync Engine
19    ///
20    /// Generally, you should initialize your `CKSyncEngine` soon after your process launches.
21    /// The sync engine will perform work in the background on your behalf, and it needs to be initialized
22    /// so that it can properly listen for push notifications and handle scheduled sync tasks.
23    ///
24    /// When initializing your sync engine, you need to provide an object conforming to the ``CKSyncEngineDelegate`` protocol.
25    /// This protocol is the main method of communication between the sync engine and your app.
26    /// You also need to provide your last known version of the ``CKSyncEngine/State/Serialization``.
27    /// See ``CKSyncEngine/State`` and ``Event/StateUpdate`` for more details on the sync engine state.
28    ///
29    /// Note that before using `CKSyncEngine` in your app, you need to add the CloudKit and remote notification capabilities.
30    ///
31    /// # Sending Changes to the Server
32    ///
33    /// In order to send changes to the server, you first need to tell the sync engine you have pending changes to send.
34    /// You can do this by adding pending changes to the sync engine's ``CKSyncEngine/state`` property.
35    ///
36    /// When you add pending changes to the state, the sync engine will schedule a task to sync.
37    /// When the sync task runs, the sync engine will start sending changes to the server.
38    /// The sync engine will automatically send database changes from ``State/pendingDatabaseChanges``, but you need to provide the record zone changes yourself.
39    /// In order to send record zone changes, you need to return them from ``CKSyncEngineDelegate/nextRecordZoneChangeBatch(_:syncEngine:)``.
40    ///
41    /// When the sync engine finishes sending a batch of changes to the server,
42    /// your `CKSyncEngineDelegate` will receive ``Event/sentDatabaseChanges(_:)`` and ``Event/sentRecordZoneChanges(_:)`` events.
43    /// These events will notify you of the success or failure of the changes you tried to send.
44    ///
45    /// At a high level, sending changes to the server happens with the following order of operations:
46    ///
47    /// 1. You add pending changes to ``CKSyncEngine/state``.
48    /// 2. You receive ``Event/willSendChanges(_:)`` in ``CKSyncEngineDelegate/handleEvent(_:syncEngine:)``
49    /// 3. If there are pending database changes, the sync engine sends the next batch.
50    /// 4. If any database changes were sent, your delegate receives``Event/sentDatabaseChanges(_:)``.
51    /// 5. Repeat from step 3 until all pending database changes are sent, then move on to record zone changes in step 6.
52    /// 6. The sync engine asks for the next batch of record zone changes by calling ``CKSyncEngineDelegate/nextRecordZoneChangeBatchToSend(_:syncEngine:)``.
53    /// 7. The sync engine sends the next record zone change batch to the server.
54    /// 8. If any record zone changes were sent, your delegate receives ``Event/sentRecordZoneChanges(_:)``.
55    /// 9. If you added any pending database changes during steps 6-8, the sync engine repeats from step 3. Otherwise, it repeats from step 6.
56    /// 10. When all pending changes are sent, your delegate receives ``Event/didSendChanges(_:)``.
57    ///
58    /// # Fetching Changes from the Server
59    ///
60    /// The sync engine will automatically listen for remote notifications, and it will fetch changes from the server when necessary.
61    /// Generally, you'll receive events in this order:
62    ///
63    /// 1. Your delegate receives ``Event/willFetchChanges(_:)``.
64    /// 2. If there are new database changes to fetch, you receive batches of them in ``Event/fetchedDatabaseChanges(_:)`` events.
65    /// 3. If there are new record zone changes to fetch, you will receive ``Event/willFetchRecordZoneChanges(_:)`` for each zone that has new changes.
66    /// 4. The sync engine fetches record zone changes and gives you batches of them in ``Event/fetchedRecordZoneChanges(_:)`` events.
67    /// 5. Your delegate receives ``Event/didFetchRecordZoneChanges(_:)`` for each zone that had changes to fetch.
68    /// 6. Your delegate receives ``Event/didFetchChanges(_:)``, indicating that sync engine has finished fetching changes.
69    ///
70    /// # Sync Scheduling
71    ///
72    /// ## Automatic sync
73    ///
74    /// By default, the sync engine will automatically schedule sync tasks on your behalf.
75    /// If the user is signed in, the device has a network connection, and the system is generally in a good state, these scheduled syncs will happen relatively quickly.
76    /// However, if the device has no network, is low on power, or is otherwise under a heavy load, these automatic syncs might be delayed.
77    /// Similarly, if the user isn't signed in to an account, the sync engine won't perform any sync tasks at all.
78    ///
79    /// ## Manual sync
80    ///
81    /// Generally, you should rely on this automatic sync behavior, but there may be some cases where you want to manually trigger a sync.
82    /// For example, if you have a pull-to-refresh UI, you can call ``CKSyncEngine/fetchChanges(_:)`` to tell the sync engine to fetch immediately.
83    /// Or if you want to provide some sort of "backup now" button, you can call ``CKSyncEngine/sendChanges(_:)`` to send to the server immediately.
84    ///
85    /// ### Testing
86    ///
87    /// These manual sync functions might also be useful during automated testing.
88    /// When writing automated tests, you can turn off automatic sync via ``CKSyncEngine/Configuration/automaticallySync``.
89    /// Then, you'll have complete control over the ordering of sync events.
90    /// This allows you to interject behavior in the sync flow and simulate specific sequences of events.
91    ///
92    /// # Error Handling
93    ///
94    /// There are some transient errors that the sync engine will handle automatically behind the scenes.
95    /// The sync engine will retry the operations for these transient errors automatically when it makes sense to do so.
96    /// Specifically, the sync engine will handle the following errors on your behalf:
97    ///
98    /// * ``CKErrorCode/notAuthenticated``
99    /// * ``CKErrorCode/accountTemporarilyUnavailable``
100    /// * ``CKErrorCode/networkFailure``
101    /// * ``CKErrorCode/networkUnavailable``
102    /// * ``CKErrorCode/requestRateLimited``
103    /// * ``CKErrorCode/serviceUnavailable``
104    /// * ``CKErrorCode/zoneBusy``
105    ///
106    /// When the sync engine encounters one of these errors, it will wait for the system to be in a good state and try again.
107    /// For example, if the server sends back a `.requestRateLimited` error, the sync engine will respect this throttle and try again after the retry-after time.
108    ///
109    /// `CKSyncEngine` will _not_ handle errors that require application-specific logic.
110    /// For example, if you try to save a record and get a ``CKErrorCode/serverRecordChanged``, you need to handle that error yourself.
111    /// There are plenty of errors that the sync engine cannot handle on your behalf, see ``CKErrorCode`` for a list of all the possible errors.
112    ///
113    /// # Accounts
114    ///
115    /// `CKSyncEngine` monitors for account status, and it will only sync if there's an account signed in.
116    /// Because of this, you can initialize your `CKSyncEngine` at any time, regardless of account status.
117    /// If there is no account, or if the user disabled sync in settings, the sync engine will stay dormant in the background.
118    /// Once an account is available, the sync engine will start syncing automatically.
119    ///
120    /// It will also listen for when the user signs in or out of their account.
121    /// When it notices an account change, it will send an ``Event/accountChange(_:)`` to your delegate.
122    /// It's your responsibility to react appropriately to this change and update your local persistence.
123    ///
124    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncengine?language=objc)
125    #[unsafe(super(NSObject))]
126    #[derive(Debug, PartialEq, Eq, Hash)]
127    pub struct CKSyncEngine;
128);
129
130unsafe impl Send for CKSyncEngine {}
131
132unsafe impl Sync for CKSyncEngine {}
133
134unsafe impl NSObjectProtocol for CKSyncEngine {}
135
136impl CKSyncEngine {
137    extern_methods!(
138        #[cfg(feature = "CKSyncEngineConfiguration")]
139        /// Initializes a `CKSyncEngine` with the given configuration.
140        /// See properties on ``CKSyncEngineConfiguration`` for more details on all the options.
141        #[unsafe(method(initWithConfiguration:))]
142        #[unsafe(method_family = init)]
143        pub unsafe fn initWithConfiguration(
144            this: Allocated<Self>,
145            configuration: &CKSyncEngineConfiguration,
146        ) -> Retained<Self>;
147
148        #[unsafe(method(init))]
149        #[unsafe(method_family = init)]
150        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
151
152        #[unsafe(method(new))]
153        #[unsafe(method_family = new)]
154        pub unsafe fn new() -> Retained<Self>;
155
156        #[cfg(feature = "CKDatabase")]
157        /// The database this sync engine will sync with.
158        #[unsafe(method(database))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn database(&self) -> Retained<CKDatabase>;
161
162        #[cfg(feature = "CKSyncEngineState")]
163        /// A collection of state properties used to efficiently manage sync engine operation.
164        /// See ``CKSyncEngineState`` for more details.
165        #[unsafe(method(state))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn state(&self) -> Retained<CKSyncEngineState>;
168
169        #[cfg(feature = "block2")]
170        /// Fetches changes from the server immediately, bypassing the system scheduler.
171        ///
172        /// By default, the sync engine will automatically fetch changes from the server for you, and you should not have to call this function.
173        /// However, you can call this if for some reason you need to ensure all changes have been fetched from the server before proceeding.
174        /// For example, you might use this in your tests to simulate specific sync scenarios.
175        ///
176        /// Fetching changes from the server might result in some events being posted to your delegate via `handleEvent`.
177        /// For example, you might receive a `CKSyncEngineWillFetchChangesEvent` or `CKSyncEngineWillFetchChangesEvent`.
178        /// This will not complete until all the relevant events have been handled by your delegate.
179        #[unsafe(method(fetchChangesWithCompletionHandler:))]
180        #[unsafe(method_family = none)]
181        pub unsafe fn fetchChangesWithCompletionHandler(
182            &self,
183            completion_handler: Option<&block2::Block<dyn Fn(*mut NSError)>>,
184        );
185
186        #[cfg(feature = "block2")]
187        /// Fetches changes from the server with the specified options.
188        /// See ``fetchChangesWithCompletionHandler:`` for more information.
189        #[unsafe(method(fetchChangesWithOptions:completionHandler:))]
190        #[unsafe(method_family = none)]
191        pub unsafe fn fetchChangesWithOptions_completionHandler(
192            &self,
193            options: &CKSyncEngineFetchChangesOptions,
194            completion_handler: Option<&block2::Block<dyn Fn(*mut NSError)>>,
195        );
196
197        #[cfg(feature = "block2")]
198        /// Sends any pending changes to the server immediately, bypassing the system scheduler.
199        ///
200        /// By default, the sync engine will automatically send changes to the server for you, and you should not have to call this function.
201        /// However, you can call this if for some reason you need to ensure all changes have been sent to the server before proceeding.
202        /// For example, you might consider using this in your tests to simulate specific sync scenarios.
203        ///
204        /// Sending changes to the server might result in some events being posted to your delegate via `handleEvent`.
205        /// For example, you might receive a `CKSyncEngineWillSendChangesEvent` or `CKSyncEngineDidSendChangesEvent`.
206        /// This function will not return until all the relevant events have been handled by your delegate.
207        #[unsafe(method(sendChangesWithCompletionHandler:))]
208        #[unsafe(method_family = none)]
209        pub unsafe fn sendChangesWithCompletionHandler(
210            &self,
211            completion_handler: Option<&block2::Block<dyn Fn(*mut NSError)>>,
212        );
213
214        #[cfg(feature = "block2")]
215        /// Sends pending changes to the server with the specified options.
216        /// See discussion in ``sendChangesWithCompletionHandler:`` for more information.
217        #[unsafe(method(sendChangesWithOptions:completionHandler:))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn sendChangesWithOptions_completionHandler(
220            &self,
221            options: &CKSyncEngineSendChangesOptions,
222            completion_handler: Option<&block2::Block<dyn Fn(*mut NSError)>>,
223        );
224
225        #[cfg(feature = "block2")]
226        /// Cancels any currently executing or pending sync operations.
227        ///
228        /// Note that cancellation does not happen synchronously, and it's possible some in-flight operations will succeed.
229        #[unsafe(method(cancelOperationsWithCompletionHandler:))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn cancelOperationsWithCompletionHandler(
232            &self,
233            completion_handler: Option<&block2::Block<dyn Fn()>>,
234        );
235    );
236}
237
238extern_protocol!(
239    /// An interface by which `CKSyncEngine` communicates with your application.
240    ///
241    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginedelegate?language=objc)
242    pub unsafe trait CKSyncEngineDelegate: NSObjectProtocol {
243        #[cfg(feature = "CKSyncEngineEvent")]
244        /// Called when an event occurs during the sync engine's operation.
245        ///
246        /// This is how you receive updates about local state changes, fetched changes, sent changes, and more.
247        /// See ``CKSyncEngineEventType`` and ``CKSyncEngineEvent`` for all the possible events that might be posted.
248        ///
249        /// ## Event ordering
250        ///
251        /// Events will be given to your delegate serially.
252        /// You will not receive the next event until you have returned from this function for the previous event.
253        #[unsafe(method(syncEngine:handleEvent:))]
254        #[unsafe(method_family = none)]
255        unsafe fn syncEngine_handleEvent(
256            &self,
257            sync_engine: &CKSyncEngine,
258            event: &CKSyncEngineEvent,
259        );
260
261        #[cfg(feature = "CKSyncEngineRecordZoneChangeBatch")]
262        /// Called to get the next batch of record zone changes to send to the server.
263        ///
264        /// The sync engine will call this function when it's about to to send changes to the server.
265        /// This might happen during an automatically scheduled sync or as a result of you calling `sendChanges`.
266        /// Provide the next batch of record zone changes to send by returning them from this function.
267        ///
268        /// Once the sync engine starts sending changes, it will continue until there are no more pending changes to send.
269        /// You can return `nil` to indicate that you have no more pending changes for now.
270        /// The next time the sync engine tries to sync, it will call this again to get any new pending changes.
271        ///
272        /// ## Sending changes for specific zones
273        ///
274        /// When you call `sendChanges` for a specific set of zone IDs, you should make sure to only send changes for those zones.
275        /// You can do this by checking the `zoneIDs` property on ``CKSyncEngineSendChangesContext/options``.
276        ///
277        /// For example, you might have some code like this:
278        ///
279        /// ```objc
280        /// - (CKSyncEngineRecordZoneChangeBatch *)syncEngine:(CKSyncEngine *)syncEngine nextRecordZoneChangeBatchForContext:(CKSyncEngineSendChangesContext *)context {
281        /// CKSyncEngineSendChangesScope *scope = context.options.scope;
282        ///
283        /// NSMutableArray
284        /// <CKSyncEnginePendingRecordZoneChange
285        /// *> *pendingChanges = [NSMutableArray new];
286        /// for (CKSyncEnginePendingRecordZoneChange *pendingChange in syncEngine.state.pendingRecordZoneChanges) {
287        /// if ([scope containsPendingRecordZoneChange:pendingChange]) {
288        /// [filteredChanges addObject:pendingChange];
289        /// }
290        /// }
291        ///
292        /// CKSyncEngineRecordZoneChangeBatch *batch = [[CKSyncEngineRecordZoneChangeBatch alloc] initWithPendingChanges:pendingChangesToSave recordProvider:^CKRecord * _Nullable(CKRecordID *recordID) {
293        /// return [self recordToSaveForRecordID:recordID];
294        /// }];
295        ///
296        /// return batch;
297        /// }
298        /// ```
299        #[unsafe(method(syncEngine:nextRecordZoneChangeBatchForContext:))]
300        #[unsafe(method_family = none)]
301        unsafe fn syncEngine_nextRecordZoneChangeBatchForContext(
302            &self,
303            sync_engine: &CKSyncEngine,
304            context: &CKSyncEngineSendChangesContext,
305        ) -> Option<Retained<CKSyncEngineRecordZoneChangeBatch>>;
306
307        /// Returns a custom set of options for `CKSyncEngine` to use while fetching changes.
308        ///
309        /// While `CKSyncEngine` fetches changes from the server, it calls this function to determine priority and other options for fetching changes.
310        /// This allows you to configure your fetches dynamically while the state changes in your app.
311        ///
312        /// For example, you can use this to prioritize fetching the object currently showing in the UI.
313        /// You can also use this to prioritize specific zones during initial sync.
314        ///
315        /// By default, `CKSyncEngine` will use whatever options are in the context.
316        /// You can return `context.options` if you don't want to perform any customization.
317        ///
318        /// This callback will be called in between each server request while fetching changes.
319        /// This allows the fetching mechanism to react dynamically while your app state changes.
320        ///
321        /// An example implementation might look something like this:
322        /// ```objc
323        /// - (CKSyncEngineFetchChangesOptions *)syncEngine:(CKSyncEngine *)syncEngine nextFetchChangesOptionsForContext:(CKSyncEngineFetchChangesContext *)context {
324        ///
325        /// // Start with the options from the context.
326        /// CKSyncEngineFetchChangesOptions *options = context.options;
327        ///
328        /// // By default, the sync engine will automatically fetch changes for all zones.
329        /// // If you know that you only want to sync a specific set of zones, you can override that here.
330        /// options.scope = [[CKSyncEngineFetchChangesScope alloc] initWithZoneIDs:
331        /// @
332        /// [...]];
333        ///
334        /// // You can prioritize specific zones to be fetched first by putting them in order.
335        /// NSMutableArray
336        /// <CKRecordZoneID
337        /// *> *prioritizedZoneIDs = [[NSMutableArray alloc] init];
338        ///
339        /// // If you're showing some data in the UI, you might want to prioritize that zone first.
340        /// CKRecordZoneID *onScreenZoneID = uiController.currentlyViewedItem.zoneID;
341        /// if (onScreenZoneID != nil) {
342        /// [prioritizedZoneIDs addObject:onScreenZoneID];
343        /// }
344        ///
345        /// // You could also prioritize special, well-known zones if that makes sense for your app.
346        /// // For example, if you have a top-level metadata zone that you'd like to sync first, you can prioritize that here.
347        /// CKRecordZoneID *topLevelZoneID = [[CKRecordZoneID alloc] initWithZoneName:
348        /// "
349        /// MyImportantMetadata"];
350        /// [prioritizedZoneIDs addObject:topLevelZoneID];
351        ///
352        /// options.prioritizedZoneIDs = prioritizedZoneIDs;
353        /// return options
354        /// }
355        /// ```
356        #[optional]
357        #[unsafe(method(syncEngine:nextFetchChangesOptionsForContext:))]
358        #[unsafe(method_family = none)]
359        unsafe fn syncEngine_nextFetchChangesOptionsForContext(
360            &self,
361            sync_engine: &CKSyncEngine,
362            context: &CKSyncEngineFetchChangesContext,
363        ) -> Retained<CKSyncEngineFetchChangesOptions>;
364    }
365);
366
367extern_class!(
368    /// A set of options to use when fetching changes from the server.
369    ///
370    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginefetchchangesoptions?language=objc)
371    #[unsafe(super(NSObject))]
372    #[derive(Debug, PartialEq, Eq, Hash)]
373    pub struct CKSyncEngineFetchChangesOptions;
374);
375
376unsafe impl Send for CKSyncEngineFetchChangesOptions {}
377
378unsafe impl Sync for CKSyncEngineFetchChangesOptions {}
379
380unsafe impl NSCopying for CKSyncEngineFetchChangesOptions {}
381
382unsafe impl CopyingHelper for CKSyncEngineFetchChangesOptions {
383    type Result = Self;
384}
385
386unsafe impl NSObjectProtocol for CKSyncEngineFetchChangesOptions {}
387
388impl CKSyncEngineFetchChangesOptions {
389    extern_methods!(
390        /// The scope in which to fetch changes from the server.
391        #[unsafe(method(scope))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn scope(&self) -> Retained<CKSyncEngineFetchChangesScope>;
394
395        /// Setter for [`scope`][Self::scope].
396        #[unsafe(method(setScope:))]
397        #[unsafe(method_family = none)]
398        pub unsafe fn setScope(&self, scope: &CKSyncEngineFetchChangesScope);
399
400        #[cfg(feature = "CKOperationGroup")]
401        /// The operation group to use for the underlying operations when fetching changes.
402        ///
403        /// You might set an operation group with a particular name in order to help you analyze telemetry in the CloudKit Console.
404        /// If you don't provide an operation group, a default one will be created for you.
405        #[unsafe(method(operationGroup))]
406        #[unsafe(method_family = none)]
407        pub unsafe fn operationGroup(&self) -> Retained<CKOperationGroup>;
408
409        #[cfg(feature = "CKOperationGroup")]
410        /// Setter for [`operationGroup`][Self::operationGroup].
411        #[unsafe(method(setOperationGroup:))]
412        #[unsafe(method_family = none)]
413        pub unsafe fn setOperationGroup(&self, operation_group: &CKOperationGroup);
414
415        #[cfg(feature = "CKRecordZoneID")]
416        /// A list of zones that should be prioritized over others while fetching changes.
417        ///
418        /// `CKSyncEngine` will fetch changes for the zones in this list first before any other zones.
419        /// You might use this to prioritize a specific set of zones for initial sync.
420        /// You could also prioritize the object currently showing in the UI by putting it first in this list.
421        ///
422        /// Any zones not included in this list will be prioritized in a default manner.
423        /// If a zone in this list has no changes to fetch, then that zone will be ignored.
424        #[unsafe(method(prioritizedZoneIDs))]
425        #[unsafe(method_family = none)]
426        pub unsafe fn prioritizedZoneIDs(&self) -> Retained<NSArray<CKRecordZoneID>>;
427
428        #[cfg(feature = "CKRecordZoneID")]
429        /// Setter for [`prioritizedZoneIDs`][Self::prioritizedZoneIDs].
430        #[unsafe(method(setPrioritizedZoneIDs:))]
431        #[unsafe(method_family = none)]
432        pub unsafe fn setPrioritizedZoneIDs(&self, prioritized_zone_i_ds: &NSArray<CKRecordZoneID>);
433
434        /// Initializes a set of options with the specific scope.
435        /// If no scope is provided, the default scope will include everything.
436        #[unsafe(method(initWithScope:))]
437        #[unsafe(method_family = init)]
438        pub unsafe fn initWithScope(
439            this: Allocated<Self>,
440            scope: Option<&CKSyncEngineFetchChangesScope>,
441        ) -> Retained<Self>;
442    );
443}
444
445/// Methods declared on superclass `NSObject`.
446impl CKSyncEngineFetchChangesOptions {
447    extern_methods!(
448        #[unsafe(method(init))]
449        #[unsafe(method_family = init)]
450        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
451
452        #[unsafe(method(new))]
453        #[unsafe(method_family = new)]
454        pub unsafe fn new() -> Retained<Self>;
455    );
456}
457
458extern_class!(
459    /// A scope in which the sync engine will fetch changes from the server.
460    ///
461    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginefetchchangesscope?language=objc)
462    #[unsafe(super(NSObject))]
463    #[derive(Debug, PartialEq, Eq, Hash)]
464    pub struct CKSyncEngineFetchChangesScope;
465);
466
467unsafe impl Send for CKSyncEngineFetchChangesScope {}
468
469unsafe impl Sync for CKSyncEngineFetchChangesScope {}
470
471unsafe impl NSCopying for CKSyncEngineFetchChangesScope {}
472
473unsafe impl CopyingHelper for CKSyncEngineFetchChangesScope {
474    type Result = Self;
475}
476
477unsafe impl NSObjectProtocol for CKSyncEngineFetchChangesScope {}
478
479impl CKSyncEngineFetchChangesScope {
480    extern_methods!(
481        #[cfg(feature = "CKRecordZoneID")]
482        /// A specific set of zone IDs to include in the scope.
483        /// For example, if you want to fetch changes for a specific set of zones, you can specify them here.
484        /// If `nil`, this scope includes all zones except those in `excludedZoneIDs`.
485        #[unsafe(method(zoneIDs))]
486        #[unsafe(method_family = none)]
487        pub unsafe fn zoneIDs(&self) -> Option<Retained<NSSet<CKRecordZoneID>>>;
488
489        #[cfg(feature = "CKRecordZoneID")]
490        /// A specific set of zone IDs to exclude from this scope.
491        /// If you know that you don't want to fetch changes for a particular set of zones, you can set those zones here.
492        #[unsafe(method(excludedZoneIDs))]
493        #[unsafe(method_family = none)]
494        pub unsafe fn excludedZoneIDs(&self) -> Retained<NSSet<CKRecordZoneID>>;
495
496        #[cfg(feature = "CKRecordZoneID")]
497        /// Creates a scope that includes only the specified set of zones.
498        #[unsafe(method(initWithZoneIDs:))]
499        #[unsafe(method_family = init)]
500        pub unsafe fn initWithZoneIDs(
501            this: Allocated<Self>,
502            zone_i_ds: Option<&NSSet<CKRecordZoneID>>,
503        ) -> Retained<Self>;
504
505        #[cfg(feature = "CKRecordZoneID")]
506        /// Creates a scope that includes all zones except the specified excluded zones.
507        #[unsafe(method(initWithExcludedZoneIDs:))]
508        #[unsafe(method_family = init)]
509        pub unsafe fn initWithExcludedZoneIDs(
510            this: Allocated<Self>,
511            zone_i_ds: &NSSet<CKRecordZoneID>,
512        ) -> Retained<Self>;
513
514        #[cfg(feature = "CKRecordZoneID")]
515        /// Returns true if the specified zone ID is included in this scope.
516        #[unsafe(method(containsZoneID:))]
517        #[unsafe(method_family = none)]
518        pub unsafe fn containsZoneID(&self, zone_id: &CKRecordZoneID) -> bool;
519    );
520}
521
522/// Methods declared on superclass `NSObject`.
523impl CKSyncEngineFetchChangesScope {
524    extern_methods!(
525        #[unsafe(method(init))]
526        #[unsafe(method_family = init)]
527        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
528
529        #[unsafe(method(new))]
530        #[unsafe(method_family = new)]
531        pub unsafe fn new() -> Retained<Self>;
532    );
533}
534
535extern_class!(
536    /// A set of options to use when sending changes to the server.
537    ///
538    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesendchangesoptions?language=objc)
539    #[unsafe(super(NSObject))]
540    #[derive(Debug, PartialEq, Eq, Hash)]
541    pub struct CKSyncEngineSendChangesOptions;
542);
543
544unsafe impl Send for CKSyncEngineSendChangesOptions {}
545
546unsafe impl Sync for CKSyncEngineSendChangesOptions {}
547
548unsafe impl NSCopying for CKSyncEngineSendChangesOptions {}
549
550unsafe impl CopyingHelper for CKSyncEngineSendChangesOptions {
551    type Result = Self;
552}
553
554unsafe impl NSObjectProtocol for CKSyncEngineSendChangesOptions {}
555
556impl CKSyncEngineSendChangesOptions {
557    extern_methods!(
558        /// The scope in which to send changes to the server.
559        #[unsafe(method(scope))]
560        #[unsafe(method_family = none)]
561        pub unsafe fn scope(&self) -> Retained<CKSyncEngineSendChangesScope>;
562
563        /// Setter for [`scope`][Self::scope].
564        #[unsafe(method(setScope:))]
565        #[unsafe(method_family = none)]
566        pub unsafe fn setScope(&self, scope: &CKSyncEngineSendChangesScope);
567
568        #[cfg(feature = "CKOperationGroup")]
569        /// The operation group to use for the underlying operations when sending changes.
570        ///
571        /// You might set an operation group with a particular name in order to help you analyze telemetry in the CloudKit Console.
572        /// If you don't provide an operation group, a default one will be created for you.
573        #[unsafe(method(operationGroup))]
574        #[unsafe(method_family = none)]
575        pub unsafe fn operationGroup(&self) -> Retained<CKOperationGroup>;
576
577        #[cfg(feature = "CKOperationGroup")]
578        /// Setter for [`operationGroup`][Self::operationGroup].
579        #[unsafe(method(setOperationGroup:))]
580        #[unsafe(method_family = none)]
581        pub unsafe fn setOperationGroup(&self, operation_group: &CKOperationGroup);
582
583        /// Initializes a set of options with the specific scope.
584        /// If no scope is provided, the default scope will include everything.
585        #[unsafe(method(initWithScope:))]
586        #[unsafe(method_family = init)]
587        pub unsafe fn initWithScope(
588            this: Allocated<Self>,
589            scope: Option<&CKSyncEngineSendChangesScope>,
590        ) -> Retained<Self>;
591    );
592}
593
594/// Methods declared on superclass `NSObject`.
595impl CKSyncEngineSendChangesOptions {
596    extern_methods!(
597        #[unsafe(method(init))]
598        #[unsafe(method_family = init)]
599        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
600
601        #[unsafe(method(new))]
602        #[unsafe(method_family = new)]
603        pub unsafe fn new() -> Retained<Self>;
604    );
605}
606
607extern_class!(
608    /// A scope in which the sync engine will send changes to  the server.
609    ///
610    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesendchangesscope?language=objc)
611    #[unsafe(super(NSObject))]
612    #[derive(Debug, PartialEq, Eq, Hash)]
613    pub struct CKSyncEngineSendChangesScope;
614);
615
616unsafe impl Send for CKSyncEngineSendChangesScope {}
617
618unsafe impl Sync for CKSyncEngineSendChangesScope {}
619
620unsafe impl NSCopying for CKSyncEngineSendChangesScope {}
621
622unsafe impl CopyingHelper for CKSyncEngineSendChangesScope {
623    type Result = Self;
624}
625
626unsafe impl NSObjectProtocol for CKSyncEngineSendChangesScope {}
627
628impl CKSyncEngineSendChangesScope {
629    extern_methods!(
630        #[cfg(feature = "CKRecordZoneID")]
631        /// The scope of zone IDs in which to send changes.
632        ///
633        /// If you only want to send changes for a particular set of zones, you can initialize your scope with those zone IDs.
634        /// When creating the next batch of changes to send to the server, consult this and only send changes within these zones.
635        /// If this and `recordIDs` are `nil`, then you should send all changes.
636        #[unsafe(method(zoneIDs))]
637        #[unsafe(method_family = none)]
638        pub unsafe fn zoneIDs(&self) -> Option<Retained<NSSet<CKRecordZoneID>>>;
639
640        #[cfg(feature = "CKRecordZoneID")]
641        /// A specific set of zone IDs to exclude from this scope.
642        /// If you know that you don't want to send changes for a particular set of zones, you can set those zones here.
643        ///
644        /// Note that if `zoneIDs` is set, then  `excludedZoneIDs` will always be empty.
645        #[unsafe(method(excludedZoneIDs))]
646        #[unsafe(method_family = none)]
647        pub unsafe fn excludedZoneIDs(&self) -> Retained<NSSet<CKRecordZoneID>>;
648
649        #[cfg(feature = "CKRecordID")]
650        /// The scope of record IDs in which to send changes.
651        ///
652        /// If you only want to send changes for a particular set of records, you can initialize your scope with those records IDs.
653        /// When creating the next batch of changes to send to the server, consult this property and only send changes for these record IDs.
654        /// If this and `zoneIDs` are `nil`, then you should send all changes.
655        #[unsafe(method(recordIDs))]
656        #[unsafe(method_family = none)]
657        pub unsafe fn recordIDs(&self) -> Option<Retained<NSSet<CKRecordID>>>;
658
659        #[cfg(feature = "CKRecordZoneID")]
660        /// Creates a scope that contains only the given zone IDs.
661        /// If `zoneIDs` is nil, then this scope contains all zones.
662        #[unsafe(method(initWithZoneIDs:))]
663        #[unsafe(method_family = init)]
664        pub unsafe fn initWithZoneIDs(
665            this: Allocated<Self>,
666            zone_i_ds: Option<&NSSet<CKRecordZoneID>>,
667        ) -> Retained<Self>;
668
669        #[cfg(feature = "CKRecordZoneID")]
670        /// Creates a scope that contains all zones except for the given zone IDs.
671        #[unsafe(method(initWithExcludedZoneIDs:))]
672        #[unsafe(method_family = init)]
673        pub unsafe fn initWithExcludedZoneIDs(
674            this: Allocated<Self>,
675            excluded_zone_i_ds: &NSSet<CKRecordZoneID>,
676        ) -> Retained<Self>;
677
678        #[cfg(feature = "CKRecordID")]
679        /// Creates a scope that includes only the given record IDs.
680        /// If `recordIDs` is nil, this scope contains all records.
681        #[unsafe(method(initWithRecordIDs:))]
682        #[unsafe(method_family = init)]
683        pub unsafe fn initWithRecordIDs(
684            this: Allocated<Self>,
685            record_i_ds: Option<&NSSet<CKRecordID>>,
686        ) -> Retained<Self>;
687
688        #[cfg(feature = "CKRecordID")]
689        /// Returns true if this scope includes the given record ID.
690        #[unsafe(method(containsRecordID:))]
691        #[unsafe(method_family = none)]
692        pub unsafe fn containsRecordID(&self, record_id: &CKRecordID) -> bool;
693
694        #[cfg(feature = "CKSyncEngineState")]
695        /// Returns true if this scope includes the given pending change.
696        #[unsafe(method(containsPendingRecordZoneChange:))]
697        #[unsafe(method_family = none)]
698        pub unsafe fn containsPendingRecordZoneChange(
699            &self,
700            pending_record_zone_change: &CKSyncEnginePendingRecordZoneChange,
701        ) -> bool;
702    );
703}
704
705/// Methods declared on superclass `NSObject`.
706impl CKSyncEngineSendChangesScope {
707    extern_methods!(
708        #[unsafe(method(init))]
709        #[unsafe(method_family = init)]
710        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
711
712        #[unsafe(method(new))]
713        #[unsafe(method_family = new)]
714        pub unsafe fn new() -> Retained<Self>;
715    );
716}
717
718/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesyncreason?language=objc)
719// NS_ENUM
720#[repr(transparent)]
721#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
722pub struct CKSyncEngineSyncReason(pub NSInteger);
723impl CKSyncEngineSyncReason {
724    /// This sync was scheduled automatically by the sync engine.
725    #[doc(alias = "CKSyncEngineSyncReasonScheduled")]
726    pub const Scheduled: Self = Self(0);
727    /// This sync was requested manually by calling `fetchChanges` or `sendChanges`.
728    #[doc(alias = "CKSyncEngineSyncReasonManual")]
729    pub const Manual: Self = Self(1);
730}
731
732unsafe impl Encode for CKSyncEngineSyncReason {
733    const ENCODING: Encoding = NSInteger::ENCODING;
734}
735
736unsafe impl RefEncode for CKSyncEngineSyncReason {
737    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
738}
739
740extern_class!(
741    /// The context of an attempt to fetch changes from the server.
742    ///
743    /// The sync engine might attempt to fetch changes to the server for many reasons.
744    /// For example, if you call `fetchChanges`, it'll try to fetch changes immediately.
745    /// Or if it receives a push notification, it'll schedule a sync and fetch changes when the scheduler task runs.
746    /// This object represents one of those attempts to fetch changes.
747    ///
748    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginefetchchangescontext?language=objc)
749    #[unsafe(super(NSObject))]
750    #[derive(Debug, PartialEq, Eq, Hash)]
751    pub struct CKSyncEngineFetchChangesContext;
752);
753
754unsafe impl Send for CKSyncEngineFetchChangesContext {}
755
756unsafe impl Sync for CKSyncEngineFetchChangesContext {}
757
758unsafe impl NSObjectProtocol for CKSyncEngineFetchChangesContext {}
759
760impl CKSyncEngineFetchChangesContext {
761    extern_methods!(
762        #[unsafe(method(init))]
763        #[unsafe(method_family = init)]
764        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
765
766        #[unsafe(method(new))]
767        #[unsafe(method_family = new)]
768        pub unsafe fn new() -> Retained<Self>;
769
770        /// The reason why the sync engine is attempting to fetch changes.
771        #[unsafe(method(reason))]
772        #[unsafe(method_family = none)]
773        pub unsafe fn reason(&self) -> CKSyncEngineSyncReason;
774
775        /// The options being used for this attempt to fetch changes.
776        #[unsafe(method(options))]
777        #[unsafe(method_family = none)]
778        pub unsafe fn options(&self) -> Retained<CKSyncEngineFetchChangesOptions>;
779    );
780}
781
782extern_class!(
783    /// The context of an attempt to send changes to the server.
784    ///
785    /// The sync engine might attempt to send changes to the server for many reasons.
786    /// For example, if you call `sendChanges`, it'll try to send changes immediately.
787    /// Or if you add pending changes to the state, it'll schedule a sync and send changes when the scheduler task runs.
788    /// This object represents one of those attempts to send changes.
789    ///
790    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesendchangescontext?language=objc)
791    #[unsafe(super(NSObject))]
792    #[derive(Debug, PartialEq, Eq, Hash)]
793    pub struct CKSyncEngineSendChangesContext;
794);
795
796unsafe impl Send for CKSyncEngineSendChangesContext {}
797
798unsafe impl Sync for CKSyncEngineSendChangesContext {}
799
800unsafe impl NSObjectProtocol for CKSyncEngineSendChangesContext {}
801
802impl CKSyncEngineSendChangesContext {
803    extern_methods!(
804        #[unsafe(method(init))]
805        #[unsafe(method_family = init)]
806        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
807
808        #[unsafe(method(new))]
809        #[unsafe(method_family = new)]
810        pub unsafe fn new() -> Retained<Self>;
811
812        /// The reason why the sync engine is attempting to send changes.
813        #[unsafe(method(reason))]
814        #[unsafe(method_family = none)]
815        pub unsafe fn reason(&self) -> CKSyncEngineSyncReason;
816
817        /// The options being used for this attempt to send changes.
818        #[unsafe(method(options))]
819        #[unsafe(method_family = none)]
820        pub unsafe fn options(&self) -> Retained<CKSyncEngineSendChangesOptions>;
821    );
822}