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
134extern_conformance!(
135    unsafe impl NSObjectProtocol for CKSyncEngine {}
136);
137
138impl CKSyncEngine {
139    extern_methods!(
140        #[cfg(feature = "CKSyncEngineConfiguration")]
141        /// Initializes a `CKSyncEngine` with the given configuration.
142        /// See properties on ``CKSyncEngineConfiguration`` for more details on all the options.
143        #[unsafe(method(initWithConfiguration:))]
144        #[unsafe(method_family = init)]
145        pub unsafe fn initWithConfiguration(
146            this: Allocated<Self>,
147            configuration: &CKSyncEngineConfiguration,
148        ) -> Retained<Self>;
149
150        #[unsafe(method(init))]
151        #[unsafe(method_family = init)]
152        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
153
154        #[unsafe(method(new))]
155        #[unsafe(method_family = new)]
156        pub unsafe fn new() -> Retained<Self>;
157
158        #[cfg(feature = "CKDatabase")]
159        /// The database this sync engine will sync with.
160        #[unsafe(method(database))]
161        #[unsafe(method_family = none)]
162        pub unsafe fn database(&self) -> Retained<CKDatabase>;
163
164        #[cfg(feature = "CKSyncEngineState")]
165        /// A collection of state properties used to efficiently manage sync engine operation.
166        /// See ``CKSyncEngineState`` for more details.
167        #[unsafe(method(state))]
168        #[unsafe(method_family = none)]
169        pub unsafe fn state(&self) -> Retained<CKSyncEngineState>;
170
171        #[cfg(feature = "block2")]
172        /// Fetches changes from the server immediately, bypassing the system scheduler.
173        ///
174        /// By default, the sync engine will automatically fetch changes from the server for you, and you should not have to call this function.
175        /// However, you can call this if for some reason you need to ensure all changes have been fetched from the server before proceeding.
176        /// For example, you might use this in your tests to simulate specific sync scenarios.
177        ///
178        /// Fetching changes from the server might result in some events being posted to your delegate via `handleEvent`.
179        /// For example, you might receive a `CKSyncEngineWillFetchChangesEvent` or `CKSyncEngineWillFetchChangesEvent`.
180        /// This will not complete until all the relevant events have been handled by your delegate.
181        #[unsafe(method(fetchChangesWithCompletionHandler:))]
182        #[unsafe(method_family = none)]
183        pub unsafe fn fetchChangesWithCompletionHandler(
184            &self,
185            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
186        );
187
188        #[cfg(feature = "block2")]
189        /// Fetches changes from the server with the specified options.
190        /// See ``fetchChangesWithCompletionHandler:`` for more information.
191        #[unsafe(method(fetchChangesWithOptions:completionHandler:))]
192        #[unsafe(method_family = none)]
193        pub unsafe fn fetchChangesWithOptions_completionHandler(
194            &self,
195            options: &CKSyncEngineFetchChangesOptions,
196            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
197        );
198
199        #[cfg(feature = "block2")]
200        /// Sends any pending changes to the server immediately, bypassing the system scheduler.
201        ///
202        /// By default, the sync engine will automatically send changes to the server for you, and you should not have to call this function.
203        /// However, you can call this if for some reason you need to ensure all changes have been sent to the server before proceeding.
204        /// For example, you might consider using this in your tests to simulate specific sync scenarios.
205        ///
206        /// Sending changes to the server might result in some events being posted to your delegate via `handleEvent`.
207        /// For example, you might receive a `CKSyncEngineWillSendChangesEvent` or `CKSyncEngineDidSendChangesEvent`.
208        /// This function will not return until all the relevant events have been handled by your delegate.
209        #[unsafe(method(sendChangesWithCompletionHandler:))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn sendChangesWithCompletionHandler(
212            &self,
213            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
214        );
215
216        #[cfg(feature = "block2")]
217        /// Sends pending changes to the server with the specified options.
218        /// See discussion in ``sendChangesWithCompletionHandler:`` for more information.
219        #[unsafe(method(sendChangesWithOptions:completionHandler:))]
220        #[unsafe(method_family = none)]
221        pub unsafe fn sendChangesWithOptions_completionHandler(
222            &self,
223            options: &CKSyncEngineSendChangesOptions,
224            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
225        );
226
227        #[cfg(feature = "block2")]
228        /// Cancels any currently executing or pending sync operations.
229        ///
230        /// Note that cancellation does not happen synchronously, and it's possible some in-flight operations will succeed.
231        #[unsafe(method(cancelOperationsWithCompletionHandler:))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn cancelOperationsWithCompletionHandler(
234            &self,
235            completion_handler: Option<&block2::DynBlock<dyn Fn()>>,
236        );
237    );
238}
239
240extern_protocol!(
241    /// An interface by which `CKSyncEngine` communicates with your application.
242    ///
243    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginedelegate?language=objc)
244    pub unsafe trait CKSyncEngineDelegate: NSObjectProtocol {
245        #[cfg(feature = "CKSyncEngineEvent")]
246        /// Called when an event occurs during the sync engine's operation.
247        ///
248        /// This is how you receive updates about local state changes, fetched changes, sent changes, and more.
249        /// See ``CKSyncEngineEventType`` and ``CKSyncEngineEvent`` for all the possible events that might be posted.
250        ///
251        /// ## Event ordering
252        ///
253        /// Events will be given to your delegate serially.
254        /// You will not receive the next event until you have returned from this function for the previous event.
255        #[unsafe(method(syncEngine:handleEvent:))]
256        #[unsafe(method_family = none)]
257        unsafe fn syncEngine_handleEvent(
258            &self,
259            sync_engine: &CKSyncEngine,
260            event: &CKSyncEngineEvent,
261        );
262
263        #[cfg(feature = "CKSyncEngineRecordZoneChangeBatch")]
264        /// Called to get the next batch of record zone changes to send to the server.
265        ///
266        /// The sync engine will call this function when it's about to to send changes to the server.
267        /// This might happen during an automatically scheduled sync or as a result of you calling `sendChanges`.
268        /// Provide the next batch of record zone changes to send by returning them from this function.
269        ///
270        /// Once the sync engine starts sending changes, it will continue until there are no more pending changes to send.
271        /// You can return `nil` to indicate that you have no more pending changes for now.
272        /// The next time the sync engine tries to sync, it will call this again to get any new pending changes.
273        ///
274        /// ## Sending changes for specific zones
275        ///
276        /// When you call `sendChanges` for a specific set of zone IDs, you should make sure to only send changes for those zones.
277        /// You can do this by checking the `zoneIDs` property on ``CKSyncEngineSendChangesContext/options``.
278        ///
279        /// For example, you might have some code like this:
280        ///
281        /// ```objc
282        /// - (CKSyncEngineRecordZoneChangeBatch *)syncEngine:(CKSyncEngine *)syncEngine nextRecordZoneChangeBatchForContext:(CKSyncEngineSendChangesContext *)context {
283        /// CKSyncEngineSendChangesScope *scope = context.options.scope;
284        ///
285        /// NSMutableArray
286        /// <CKSyncEnginePendingRecordZoneChange
287        /// *> *pendingChanges = [NSMutableArray new];
288        /// for (CKSyncEnginePendingRecordZoneChange *pendingChange in syncEngine.state.pendingRecordZoneChanges) {
289        /// if ([scope containsPendingRecordZoneChange:pendingChange]) {
290        /// [filteredChanges addObject:pendingChange];
291        /// }
292        /// }
293        ///
294        /// CKSyncEngineRecordZoneChangeBatch *batch = [[CKSyncEngineRecordZoneChangeBatch alloc] initWithPendingChanges:pendingChangesToSave recordProvider:^CKRecord * _Nullable(CKRecordID *recordID) {
295        /// return [self recordToSaveForRecordID:recordID];
296        /// }];
297        ///
298        /// return batch;
299        /// }
300        /// ```
301        #[unsafe(method(syncEngine:nextRecordZoneChangeBatchForContext:))]
302        #[unsafe(method_family = none)]
303        unsafe fn syncEngine_nextRecordZoneChangeBatchForContext(
304            &self,
305            sync_engine: &CKSyncEngine,
306            context: &CKSyncEngineSendChangesContext,
307        ) -> Option<Retained<CKSyncEngineRecordZoneChangeBatch>>;
308
309        /// Returns a custom set of options for `CKSyncEngine` to use while fetching changes.
310        ///
311        /// While `CKSyncEngine` fetches changes from the server, it calls this function to determine priority and other options for fetching changes.
312        /// This allows you to configure your fetches dynamically while the state changes in your app.
313        ///
314        /// For example, you can use this to prioritize fetching the object currently showing in the UI.
315        /// You can also use this to prioritize specific zones during initial sync.
316        ///
317        /// By default, `CKSyncEngine` will use whatever options are in the context.
318        /// You can return `context.options` if you don't want to perform any customization.
319        ///
320        /// This callback will be called in between each server request while fetching changes.
321        /// This allows the fetching mechanism to react dynamically while your app state changes.
322        ///
323        /// An example implementation might look something like this:
324        /// ```objc
325        /// - (CKSyncEngineFetchChangesOptions *)syncEngine:(CKSyncEngine *)syncEngine nextFetchChangesOptionsForContext:(CKSyncEngineFetchChangesContext *)context {
326        ///
327        /// // Start with the options from the context.
328        /// CKSyncEngineFetchChangesOptions *options = context.options;
329        ///
330        /// // By default, the sync engine will automatically fetch changes for all zones.
331        /// // If you know that you only want to sync a specific set of zones, you can override that here.
332        /// options.scope = [[CKSyncEngineFetchChangesScope alloc] initWithZoneIDs:
333        /// @
334        /// [...]];
335        ///
336        /// // You can prioritize specific zones to be fetched first by putting them in order.
337        /// NSMutableArray
338        /// <CKRecordZoneID
339        /// *> *prioritizedZoneIDs = [[NSMutableArray alloc] init];
340        ///
341        /// // If you're showing some data in the UI, you might want to prioritize that zone first.
342        /// CKRecordZoneID *onScreenZoneID = uiController.currentlyViewedItem.zoneID;
343        /// if (onScreenZoneID != nil) {
344        /// [prioritizedZoneIDs addObject:onScreenZoneID];
345        /// }
346        ///
347        /// // You could also prioritize special, well-known zones if that makes sense for your app.
348        /// // For example, if you have a top-level metadata zone that you'd like to sync first, you can prioritize that here.
349        /// CKRecordZoneID *topLevelZoneID = [[CKRecordZoneID alloc] initWithZoneName:
350        /// "
351        /// MyImportantMetadata"];
352        /// [prioritizedZoneIDs addObject:topLevelZoneID];
353        ///
354        /// options.prioritizedZoneIDs = prioritizedZoneIDs;
355        /// return options
356        /// }
357        /// ```
358        #[optional]
359        #[unsafe(method(syncEngine:nextFetchChangesOptionsForContext:))]
360        #[unsafe(method_family = none)]
361        unsafe fn syncEngine_nextFetchChangesOptionsForContext(
362            &self,
363            sync_engine: &CKSyncEngine,
364            context: &CKSyncEngineFetchChangesContext,
365        ) -> Retained<CKSyncEngineFetchChangesOptions>;
366    }
367);
368
369extern_class!(
370    /// A set of options to use when fetching changes from the server.
371    ///
372    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginefetchchangesoptions?language=objc)
373    #[unsafe(super(NSObject))]
374    #[derive(Debug, PartialEq, Eq, Hash)]
375    pub struct CKSyncEngineFetchChangesOptions;
376);
377
378unsafe impl Send for CKSyncEngineFetchChangesOptions {}
379
380unsafe impl Sync for CKSyncEngineFetchChangesOptions {}
381
382extern_conformance!(
383    unsafe impl NSCopying for CKSyncEngineFetchChangesOptions {}
384);
385
386unsafe impl CopyingHelper for CKSyncEngineFetchChangesOptions {
387    type Result = Self;
388}
389
390extern_conformance!(
391    unsafe impl NSObjectProtocol for CKSyncEngineFetchChangesOptions {}
392);
393
394impl CKSyncEngineFetchChangesOptions {
395    extern_methods!(
396        /// The scope in which to fetch changes from the server.
397        #[unsafe(method(scope))]
398        #[unsafe(method_family = none)]
399        pub unsafe fn scope(&self) -> Retained<CKSyncEngineFetchChangesScope>;
400
401        /// Setter for [`scope`][Self::scope].
402        #[unsafe(method(setScope:))]
403        #[unsafe(method_family = none)]
404        pub unsafe fn setScope(&self, scope: &CKSyncEngineFetchChangesScope);
405
406        #[cfg(feature = "CKOperationGroup")]
407        /// The operation group to use for the underlying operations when fetching changes.
408        ///
409        /// You might set an operation group with a particular name in order to help you analyze telemetry in the CloudKit Console.
410        /// If you don't provide an operation group, a default one will be created for you.
411        #[unsafe(method(operationGroup))]
412        #[unsafe(method_family = none)]
413        pub unsafe fn operationGroup(&self) -> Retained<CKOperationGroup>;
414
415        #[cfg(feature = "CKOperationGroup")]
416        /// Setter for [`operationGroup`][Self::operationGroup].
417        #[unsafe(method(setOperationGroup:))]
418        #[unsafe(method_family = none)]
419        pub unsafe fn setOperationGroup(&self, operation_group: &CKOperationGroup);
420
421        #[cfg(feature = "CKRecordZoneID")]
422        /// A list of zones that should be prioritized over others while fetching changes.
423        ///
424        /// `CKSyncEngine` will fetch changes for the zones in this list first before any other zones.
425        /// You might use this to prioritize a specific set of zones for initial sync.
426        /// You could also prioritize the object currently showing in the UI by putting it first in this list.
427        ///
428        /// Any zones not included in this list will be prioritized in a default manner.
429        /// If a zone in this list has no changes to fetch, then that zone will be ignored.
430        #[unsafe(method(prioritizedZoneIDs))]
431        #[unsafe(method_family = none)]
432        pub unsafe fn prioritizedZoneIDs(&self) -> Retained<NSArray<CKRecordZoneID>>;
433
434        #[cfg(feature = "CKRecordZoneID")]
435        /// Setter for [`prioritizedZoneIDs`][Self::prioritizedZoneIDs].
436        #[unsafe(method(setPrioritizedZoneIDs:))]
437        #[unsafe(method_family = none)]
438        pub unsafe fn setPrioritizedZoneIDs(&self, prioritized_zone_i_ds: &NSArray<CKRecordZoneID>);
439
440        /// Initializes a set of options with the specific scope.
441        /// If no scope is provided, the default scope will include everything.
442        #[unsafe(method(initWithScope:))]
443        #[unsafe(method_family = init)]
444        pub unsafe fn initWithScope(
445            this: Allocated<Self>,
446            scope: Option<&CKSyncEngineFetchChangesScope>,
447        ) -> Retained<Self>;
448    );
449}
450
451/// Methods declared on superclass `NSObject`.
452impl CKSyncEngineFetchChangesOptions {
453    extern_methods!(
454        #[unsafe(method(init))]
455        #[unsafe(method_family = init)]
456        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
457
458        #[unsafe(method(new))]
459        #[unsafe(method_family = new)]
460        pub unsafe fn new() -> Retained<Self>;
461    );
462}
463
464extern_class!(
465    /// A scope in which the sync engine will fetch changes from the server.
466    ///
467    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginefetchchangesscope?language=objc)
468    #[unsafe(super(NSObject))]
469    #[derive(Debug, PartialEq, Eq, Hash)]
470    pub struct CKSyncEngineFetchChangesScope;
471);
472
473unsafe impl Send for CKSyncEngineFetchChangesScope {}
474
475unsafe impl Sync for CKSyncEngineFetchChangesScope {}
476
477extern_conformance!(
478    unsafe impl NSCopying for CKSyncEngineFetchChangesScope {}
479);
480
481unsafe impl CopyingHelper for CKSyncEngineFetchChangesScope {
482    type Result = Self;
483}
484
485extern_conformance!(
486    unsafe impl NSObjectProtocol for CKSyncEngineFetchChangesScope {}
487);
488
489impl CKSyncEngineFetchChangesScope {
490    extern_methods!(
491        #[cfg(feature = "CKRecordZoneID")]
492        /// A specific set of zone IDs to include in the scope.
493        /// For example, if you want to fetch changes for a specific set of zones, you can specify them here.
494        /// If `nil`, this scope includes all zones except those in `excludedZoneIDs`.
495        #[unsafe(method(zoneIDs))]
496        #[unsafe(method_family = none)]
497        pub unsafe fn zoneIDs(&self) -> Option<Retained<NSSet<CKRecordZoneID>>>;
498
499        #[cfg(feature = "CKRecordZoneID")]
500        /// A specific set of zone IDs to exclude from this scope.
501        /// If you know that you don't want to fetch changes for a particular set of zones, you can set those zones here.
502        #[unsafe(method(excludedZoneIDs))]
503        #[unsafe(method_family = none)]
504        pub unsafe fn excludedZoneIDs(&self) -> Retained<NSSet<CKRecordZoneID>>;
505
506        #[cfg(feature = "CKRecordZoneID")]
507        /// Creates a scope that includes only the specified set of zones.
508        #[unsafe(method(initWithZoneIDs:))]
509        #[unsafe(method_family = init)]
510        pub unsafe fn initWithZoneIDs(
511            this: Allocated<Self>,
512            zone_i_ds: Option<&NSSet<CKRecordZoneID>>,
513        ) -> Retained<Self>;
514
515        #[cfg(feature = "CKRecordZoneID")]
516        /// Creates a scope that includes all zones except the specified excluded zones.
517        #[unsafe(method(initWithExcludedZoneIDs:))]
518        #[unsafe(method_family = init)]
519        pub unsafe fn initWithExcludedZoneIDs(
520            this: Allocated<Self>,
521            zone_i_ds: &NSSet<CKRecordZoneID>,
522        ) -> Retained<Self>;
523
524        #[cfg(feature = "CKRecordZoneID")]
525        /// Returns true if the specified zone ID is included in this scope.
526        #[unsafe(method(containsZoneID:))]
527        #[unsafe(method_family = none)]
528        pub unsafe fn containsZoneID(&self, zone_id: &CKRecordZoneID) -> bool;
529    );
530}
531
532/// Methods declared on superclass `NSObject`.
533impl CKSyncEngineFetchChangesScope {
534    extern_methods!(
535        #[unsafe(method(init))]
536        #[unsafe(method_family = init)]
537        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
538
539        #[unsafe(method(new))]
540        #[unsafe(method_family = new)]
541        pub unsafe fn new() -> Retained<Self>;
542    );
543}
544
545extern_class!(
546    /// A set of options to use when sending changes to the server.
547    ///
548    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesendchangesoptions?language=objc)
549    #[unsafe(super(NSObject))]
550    #[derive(Debug, PartialEq, Eq, Hash)]
551    pub struct CKSyncEngineSendChangesOptions;
552);
553
554unsafe impl Send for CKSyncEngineSendChangesOptions {}
555
556unsafe impl Sync for CKSyncEngineSendChangesOptions {}
557
558extern_conformance!(
559    unsafe impl NSCopying for CKSyncEngineSendChangesOptions {}
560);
561
562unsafe impl CopyingHelper for CKSyncEngineSendChangesOptions {
563    type Result = Self;
564}
565
566extern_conformance!(
567    unsafe impl NSObjectProtocol for CKSyncEngineSendChangesOptions {}
568);
569
570impl CKSyncEngineSendChangesOptions {
571    extern_methods!(
572        /// The scope in which to send changes to the server.
573        #[unsafe(method(scope))]
574        #[unsafe(method_family = none)]
575        pub unsafe fn scope(&self) -> Retained<CKSyncEngineSendChangesScope>;
576
577        /// Setter for [`scope`][Self::scope].
578        #[unsafe(method(setScope:))]
579        #[unsafe(method_family = none)]
580        pub unsafe fn setScope(&self, scope: &CKSyncEngineSendChangesScope);
581
582        #[cfg(feature = "CKOperationGroup")]
583        /// The operation group to use for the underlying operations when sending changes.
584        ///
585        /// You might set an operation group with a particular name in order to help you analyze telemetry in the CloudKit Console.
586        /// If you don't provide an operation group, a default one will be created for you.
587        #[unsafe(method(operationGroup))]
588        #[unsafe(method_family = none)]
589        pub unsafe fn operationGroup(&self) -> Retained<CKOperationGroup>;
590
591        #[cfg(feature = "CKOperationGroup")]
592        /// Setter for [`operationGroup`][Self::operationGroup].
593        #[unsafe(method(setOperationGroup:))]
594        #[unsafe(method_family = none)]
595        pub unsafe fn setOperationGroup(&self, operation_group: &CKOperationGroup);
596
597        /// Initializes a set of options with the specific scope.
598        /// If no scope is provided, the default scope will include everything.
599        #[unsafe(method(initWithScope:))]
600        #[unsafe(method_family = init)]
601        pub unsafe fn initWithScope(
602            this: Allocated<Self>,
603            scope: Option<&CKSyncEngineSendChangesScope>,
604        ) -> Retained<Self>;
605    );
606}
607
608/// Methods declared on superclass `NSObject`.
609impl CKSyncEngineSendChangesOptions {
610    extern_methods!(
611        #[unsafe(method(init))]
612        #[unsafe(method_family = init)]
613        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
614
615        #[unsafe(method(new))]
616        #[unsafe(method_family = new)]
617        pub unsafe fn new() -> Retained<Self>;
618    );
619}
620
621extern_class!(
622    /// A scope in which the sync engine will send changes to  the server.
623    ///
624    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesendchangesscope?language=objc)
625    #[unsafe(super(NSObject))]
626    #[derive(Debug, PartialEq, Eq, Hash)]
627    pub struct CKSyncEngineSendChangesScope;
628);
629
630unsafe impl Send for CKSyncEngineSendChangesScope {}
631
632unsafe impl Sync for CKSyncEngineSendChangesScope {}
633
634extern_conformance!(
635    unsafe impl NSCopying for CKSyncEngineSendChangesScope {}
636);
637
638unsafe impl CopyingHelper for CKSyncEngineSendChangesScope {
639    type Result = Self;
640}
641
642extern_conformance!(
643    unsafe impl NSObjectProtocol for CKSyncEngineSendChangesScope {}
644);
645
646impl CKSyncEngineSendChangesScope {
647    extern_methods!(
648        #[cfg(feature = "CKRecordZoneID")]
649        /// The scope of zone IDs in which to send changes.
650        ///
651        /// If you only want to send changes for a particular set of zones, you can initialize your scope with those zone IDs.
652        /// When creating the next batch of changes to send to the server, consult this and only send changes within these zones.
653        /// If this and `recordIDs` are `nil`, then you should send all changes.
654        #[unsafe(method(zoneIDs))]
655        #[unsafe(method_family = none)]
656        pub unsafe fn zoneIDs(&self) -> Option<Retained<NSSet<CKRecordZoneID>>>;
657
658        #[cfg(feature = "CKRecordZoneID")]
659        /// A specific set of zone IDs to exclude from this scope.
660        /// If you know that you don't want to send changes for a particular set of zones, you can set those zones here.
661        ///
662        /// Note that if `zoneIDs` is set, then  `excludedZoneIDs` will always be empty.
663        #[unsafe(method(excludedZoneIDs))]
664        #[unsafe(method_family = none)]
665        pub unsafe fn excludedZoneIDs(&self) -> Retained<NSSet<CKRecordZoneID>>;
666
667        #[cfg(feature = "CKRecordID")]
668        /// The scope of record IDs in which to send changes.
669        ///
670        /// If you only want to send changes for a particular set of records, you can initialize your scope with those records IDs.
671        /// When creating the next batch of changes to send to the server, consult this property and only send changes for these record IDs.
672        /// If this and `zoneIDs` are `nil`, then you should send all changes.
673        #[unsafe(method(recordIDs))]
674        #[unsafe(method_family = none)]
675        pub unsafe fn recordIDs(&self) -> Option<Retained<NSSet<CKRecordID>>>;
676
677        #[cfg(feature = "CKRecordZoneID")]
678        /// Creates a scope that contains only the given zone IDs.
679        /// If `zoneIDs` is nil, then this scope contains all zones.
680        #[unsafe(method(initWithZoneIDs:))]
681        #[unsafe(method_family = init)]
682        pub unsafe fn initWithZoneIDs(
683            this: Allocated<Self>,
684            zone_i_ds: Option<&NSSet<CKRecordZoneID>>,
685        ) -> Retained<Self>;
686
687        #[cfg(feature = "CKRecordZoneID")]
688        /// Creates a scope that contains all zones except for the given zone IDs.
689        #[unsafe(method(initWithExcludedZoneIDs:))]
690        #[unsafe(method_family = init)]
691        pub unsafe fn initWithExcludedZoneIDs(
692            this: Allocated<Self>,
693            excluded_zone_i_ds: &NSSet<CKRecordZoneID>,
694        ) -> Retained<Self>;
695
696        #[cfg(feature = "CKRecordID")]
697        /// Creates a scope that includes only the given record IDs.
698        /// If `recordIDs` is nil, this scope contains all records.
699        #[unsafe(method(initWithRecordIDs:))]
700        #[unsafe(method_family = init)]
701        pub unsafe fn initWithRecordIDs(
702            this: Allocated<Self>,
703            record_i_ds: Option<&NSSet<CKRecordID>>,
704        ) -> Retained<Self>;
705
706        #[cfg(feature = "CKRecordID")]
707        /// Returns true if this scope includes the given record ID.
708        #[unsafe(method(containsRecordID:))]
709        #[unsafe(method_family = none)]
710        pub unsafe fn containsRecordID(&self, record_id: &CKRecordID) -> bool;
711
712        #[cfg(feature = "CKSyncEngineState")]
713        /// Returns true if this scope includes the given pending change.
714        #[unsafe(method(containsPendingRecordZoneChange:))]
715        #[unsafe(method_family = none)]
716        pub unsafe fn containsPendingRecordZoneChange(
717            &self,
718            pending_record_zone_change: &CKSyncEnginePendingRecordZoneChange,
719        ) -> bool;
720    );
721}
722
723/// Methods declared on superclass `NSObject`.
724impl CKSyncEngineSendChangesScope {
725    extern_methods!(
726        #[unsafe(method(init))]
727        #[unsafe(method_family = init)]
728        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
729
730        #[unsafe(method(new))]
731        #[unsafe(method_family = new)]
732        pub unsafe fn new() -> Retained<Self>;
733    );
734}
735
736/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesyncreason?language=objc)
737// NS_ENUM
738#[repr(transparent)]
739#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
740pub struct CKSyncEngineSyncReason(pub NSInteger);
741impl CKSyncEngineSyncReason {
742    /// This sync was scheduled automatically by the sync engine.
743    #[doc(alias = "CKSyncEngineSyncReasonScheduled")]
744    pub const Scheduled: Self = Self(0);
745    /// This sync was requested manually by calling `fetchChanges` or `sendChanges`.
746    #[doc(alias = "CKSyncEngineSyncReasonManual")]
747    pub const Manual: Self = Self(1);
748}
749
750unsafe impl Encode for CKSyncEngineSyncReason {
751    const ENCODING: Encoding = NSInteger::ENCODING;
752}
753
754unsafe impl RefEncode for CKSyncEngineSyncReason {
755    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
756}
757
758extern_class!(
759    /// The context of an attempt to fetch changes from the server.
760    ///
761    /// The sync engine might attempt to fetch changes to the server for many reasons.
762    /// For example, if you call `fetchChanges`, it'll try to fetch changes immediately.
763    /// Or if it receives a push notification, it'll schedule a sync and fetch changes when the scheduler task runs.
764    /// This object represents one of those attempts to fetch changes.
765    ///
766    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginefetchchangescontext?language=objc)
767    #[unsafe(super(NSObject))]
768    #[derive(Debug, PartialEq, Eq, Hash)]
769    pub struct CKSyncEngineFetchChangesContext;
770);
771
772unsafe impl Send for CKSyncEngineFetchChangesContext {}
773
774unsafe impl Sync for CKSyncEngineFetchChangesContext {}
775
776extern_conformance!(
777    unsafe impl NSObjectProtocol for CKSyncEngineFetchChangesContext {}
778);
779
780impl CKSyncEngineFetchChangesContext {
781    extern_methods!(
782        #[unsafe(method(init))]
783        #[unsafe(method_family = init)]
784        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
785
786        #[unsafe(method(new))]
787        #[unsafe(method_family = new)]
788        pub unsafe fn new() -> Retained<Self>;
789
790        /// The reason why the sync engine is attempting to fetch changes.
791        #[unsafe(method(reason))]
792        #[unsafe(method_family = none)]
793        pub unsafe fn reason(&self) -> CKSyncEngineSyncReason;
794
795        /// The options being used for this attempt to fetch changes.
796        #[unsafe(method(options))]
797        #[unsafe(method_family = none)]
798        pub unsafe fn options(&self) -> Retained<CKSyncEngineFetchChangesOptions>;
799    );
800}
801
802extern_class!(
803    /// The context of an attempt to send changes to the server.
804    ///
805    /// The sync engine might attempt to send changes to the server for many reasons.
806    /// For example, if you call `sendChanges`, it'll try to send changes immediately.
807    /// Or if you add pending changes to the state, it'll schedule a sync and send changes when the scheduler task runs.
808    /// This object represents one of those attempts to send changes.
809    ///
810    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginesendchangescontext?language=objc)
811    #[unsafe(super(NSObject))]
812    #[derive(Debug, PartialEq, Eq, Hash)]
813    pub struct CKSyncEngineSendChangesContext;
814);
815
816unsafe impl Send for CKSyncEngineSendChangesContext {}
817
818unsafe impl Sync for CKSyncEngineSendChangesContext {}
819
820extern_conformance!(
821    unsafe impl NSObjectProtocol for CKSyncEngineSendChangesContext {}
822);
823
824impl CKSyncEngineSendChangesContext {
825    extern_methods!(
826        #[unsafe(method(init))]
827        #[unsafe(method_family = init)]
828        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
829
830        #[unsafe(method(new))]
831        #[unsafe(method_family = new)]
832        pub unsafe fn new() -> Retained<Self>;
833
834        /// The reason why the sync engine is attempting to send changes.
835        #[unsafe(method(reason))]
836        #[unsafe(method_family = none)]
837        pub unsafe fn reason(&self) -> CKSyncEngineSyncReason;
838
839        /// The options being used for this attempt to send changes.
840        #[unsafe(method(options))]
841        #[unsafe(method_family = none)]
842        pub unsafe fn options(&self) -> Retained<CKSyncEngineSendChangesOptions>;
843    );
844}