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