objc2-cloud-kit 0.3.2

Bindings to the CloudKit framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// An object that tracks some state required for proper and efficient operation of ``CKSyncEngine-5sie5``.
    ///
    /// ``CKSyncEngine-5sie5`` needs to track several things in order to properly sync.
    /// For example, it needs to remember the last server change tokens for your database and zones.
    /// It also needs to keep track of things like the last known user record ID and other various pieces of state.
    ///
    /// A lot of this state is hidden internally, but some of it you can control.
    ///
    /// ## Pending changes
    ///
    /// One of the main things you can control is the list of pending changes to send to the server.
    /// You can control these by calling functions like ``addPendingDatabaseChanges:`` and ``addPendingRecordZoneChanges:``.
    /// When you add new pending changes, the sync engine will automatically schedule a task to sync with the server.
    ///
    /// ## State serialization
    ///
    /// ``CKSyncEngine-5sie5`` will occasionally update its state in the background.
    /// When it updates its state, your delegate will receive a ``CKSyncEngineStateUpdateEvent``.
    ///
    /// This event will contain a ``CKSyncEngineStateSerialization``, which you should persist locally.
    /// The next time your process launches, you initialize your sync engine with the last state serialization you received.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginestate?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKSyncEngineState;
);

unsafe impl Send for CKSyncEngineState {}

unsafe impl Sync for CKSyncEngineState {}

extern_conformance!(
    unsafe impl NSObjectProtocol for CKSyncEngineState {}
);

impl CKSyncEngineState {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        /// A list of record changes that need to be sent to the server.
        ///
        /// ``CKSyncEngine-5sie5`` provides the convenience of tracking your pending record zone changes.
        /// When the user makes some changes that need to be sent to the server, you can track them in this list.
        /// Then, you can use this list when creating your next ``CKSyncEngineRecordZoneChangeBatch`` in your ``CKSyncEngineDelegate-1q7g8``.
        ///
        /// The sync engine will ensure consistency and deduplicate these pending changes under the hood.
        /// For example, if you add a pending save for record A, then record B, then record A again, this will result in a list of `[saveRecordA, saveRecordB]`.
        /// Similarly, if you add a pending save for record A, then add a pending delete for the same record A, this will result in a single pending change of `[deleteRecordA]`.
        ///
        /// The sync engine will manage this list while it sends changes to the server.
        /// For example, when it successfully saves a record, it will remove that change from this list.
        /// If it fails to send a change due to some retryable error (e.g. a network failure), it will keep that change in this list.
        ///
        /// If you'd prefer to track pending changes yourself, you can use ``CKSyncEngine/State/hasPendingUntrackedChanges`` instead.
        #[unsafe(method(pendingRecordZoneChanges))]
        #[unsafe(method_family = none)]
        pub unsafe fn pendingRecordZoneChanges(
            &self,
        ) -> Retained<NSArray<CKSyncEnginePendingRecordZoneChange>>;

        /// A list of database changes that need to be sent to the server, similar to `pendingRecordZoneChanges`.
        #[unsafe(method(pendingDatabaseChanges))]
        #[unsafe(method_family = none)]
        pub unsafe fn pendingDatabaseChanges(
            &self,
        ) -> Retained<NSArray<CKSyncEnginePendingDatabaseChange>>;

        /// This represents whether or not you have pending changes to send to the server that aren't tracked in ``CKSyncEngine/State/pendingRecordZoneChanges``.
        /// This is useful if you want to track pending changes in your own local database instead of the sync engine state.
        ///
        /// When this property is set, the sync engine will automatically schedule a sync.
        /// When the sync task runs, it will ask your delegate for pending changes in ``CKSyncEngineDelegate/nextRecordZoneChangeBatch(_:syncEngine:)``.
        #[unsafe(method(hasPendingUntrackedChanges))]
        #[unsafe(method_family = none)]
        pub unsafe fn hasPendingUntrackedChanges(&self) -> bool;

        /// Setter for [`hasPendingUntrackedChanges`][Self::hasPendingUntrackedChanges].
        #[unsafe(method(setHasPendingUntrackedChanges:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHasPendingUntrackedChanges(&self, has_pending_untracked_changes: bool);

        #[cfg(feature = "CKRecordZoneID")]
        /// The list of zone IDs that have new changes to fetch from the server.
        /// ``CKSyncEngine-5sie5`` keeps track of these zones and will update this list as it receives new information.
        #[unsafe(method(zoneIDsWithUnfetchedServerChanges))]
        #[unsafe(method_family = none)]
        pub unsafe fn zoneIDsWithUnfetchedServerChanges(&self)
            -> Retained<NSArray<CKRecordZoneID>>;

        /// Adds to the list of pending record zone changes.
        ///
        /// When you add a new pending change, the sync engine will automatically schedule a sync task.
        ///
        /// The sync engine will ensure consistency and deduplicate these changes under the hood.
        #[unsafe(method(addPendingRecordZoneChanges:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addPendingRecordZoneChanges(
            &self,
            changes: &NSArray<CKSyncEnginePendingRecordZoneChange>,
        );

        /// Removes from the list of pending record zone changes.
        #[unsafe(method(removePendingRecordZoneChanges:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removePendingRecordZoneChanges(
            &self,
            changes: &NSArray<CKSyncEnginePendingRecordZoneChange>,
        );

        /// Adds to the list of pending database changes.
        ///
        /// When you add a new pending change, the sync engine will automatically schedule a sync task.
        ///
        /// The sync engine will ensure consistency and deduplicate these changes under the hood.
        #[unsafe(method(addPendingDatabaseChanges:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addPendingDatabaseChanges(
            &self,
            changes: &NSArray<CKSyncEnginePendingDatabaseChange>,
        );

        /// Removes from the list of pending database changes.
        #[unsafe(method(removePendingDatabaseChanges:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removePendingDatabaseChanges(
            &self,
            changes: &NSArray<CKSyncEnginePendingDatabaseChange>,
        );
    );
}

extern_class!(
    /// A serialized representation of a ``CKSyncEngineState``.
    ///
    /// This will be passed to your delegate via ``CKSyncEngine/Event/StateUpdate``.
    /// You should use `NSSecureCoding` to persist this locally alongside your other data and use it the next time you initialize your sync engine.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginestateserialization?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKSyncEngineStateSerialization;
);

unsafe impl Send for CKSyncEngineStateSerialization {}

unsafe impl Sync for CKSyncEngineStateSerialization {}

extern_conformance!(
    unsafe impl NSCoding for CKSyncEngineStateSerialization {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for CKSyncEngineStateSerialization {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for CKSyncEngineStateSerialization {}
);

impl CKSyncEngineStateSerialization {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingrecordzonechangetype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CKSyncEnginePendingRecordZoneChangeType(pub NSInteger);
impl CKSyncEnginePendingRecordZoneChangeType {
    #[doc(alias = "CKSyncEnginePendingRecordZoneChangeTypeSaveRecord")]
    pub const SaveRecord: Self = Self(0);
    #[doc(alias = "CKSyncEnginePendingRecordZoneChangeTypeDeleteRecord")]
    pub const DeleteRecord: Self = Self(1);
}

unsafe impl Encode for CKSyncEnginePendingRecordZoneChangeType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for CKSyncEnginePendingRecordZoneChangeType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// A change in a record zone that needs to be sent to the server.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingrecordzonechange?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKSyncEnginePendingRecordZoneChange;
);

unsafe impl Send for CKSyncEnginePendingRecordZoneChange {}

unsafe impl Sync for CKSyncEnginePendingRecordZoneChange {}

extern_conformance!(
    unsafe impl NSObjectProtocol for CKSyncEnginePendingRecordZoneChange {}
);

impl CKSyncEnginePendingRecordZoneChange {
    extern_methods!(
        #[cfg(feature = "CKRecordID")]
        #[unsafe(method(initWithRecordID:type:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithRecordID_type(
            this: Allocated<Self>,
            record_id: &CKRecordID,
            r#type: CKSyncEnginePendingRecordZoneChangeType,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[cfg(feature = "CKRecordID")]
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(recordID))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordID(&self) -> Retained<CKRecordID>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub unsafe fn r#type(&self) -> CKSyncEnginePendingRecordZoneChangeType;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingdatabasechangetype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CKSyncEnginePendingDatabaseChangeType(pub NSInteger);
impl CKSyncEnginePendingDatabaseChangeType {
    #[doc(alias = "CKSyncEnginePendingDatabaseChangeTypeSaveZone")]
    pub const SaveZone: Self = Self(0);
    #[doc(alias = "CKSyncEnginePendingDatabaseChangeTypeDeleteZone")]
    pub const DeleteZone: Self = Self(1);
}

unsafe impl Encode for CKSyncEnginePendingDatabaseChangeType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for CKSyncEnginePendingDatabaseChangeType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// A change in a database that needs to be sent to the server.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingdatabasechange?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKSyncEnginePendingDatabaseChange;
);

unsafe impl Send for CKSyncEnginePendingDatabaseChange {}

unsafe impl Sync for CKSyncEnginePendingDatabaseChange {}

extern_conformance!(
    unsafe impl NSObjectProtocol for CKSyncEnginePendingDatabaseChange {}
);

impl CKSyncEnginePendingDatabaseChange {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[cfg(feature = "CKRecordZoneID")]
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(zoneID))]
        #[unsafe(method_family = none)]
        pub unsafe fn zoneID(&self) -> Retained<CKRecordZoneID>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub unsafe fn r#type(&self) -> CKSyncEnginePendingDatabaseChangeType;
    );
}

extern_class!(
    /// A zone save that needs to be sent to the server.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingzonesave?language=objc)
    #[unsafe(super(CKSyncEnginePendingDatabaseChange, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKSyncEnginePendingZoneSave;
);

unsafe impl Send for CKSyncEnginePendingZoneSave {}

unsafe impl Sync for CKSyncEnginePendingZoneSave {}

extern_conformance!(
    unsafe impl NSObjectProtocol for CKSyncEnginePendingZoneSave {}
);

impl CKSyncEnginePendingZoneSave {
    extern_methods!(
        #[cfg(feature = "CKRecordZone")]
        #[unsafe(method(initWithZone:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithZone(this: Allocated<Self>, zone: &CKRecordZone) -> Retained<Self>;

        #[cfg(feature = "CKRecordZone")]
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(zone))]
        #[unsafe(method_family = none)]
        pub unsafe fn zone(&self) -> Retained<CKRecordZone>;
    );
}

/// Methods declared on superclass `CKSyncEnginePendingDatabaseChange`.
impl CKSyncEnginePendingZoneSave {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// A zone delete that needs to be sent to the server.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/cksyncenginependingzonedelete?language=objc)
    #[unsafe(super(CKSyncEnginePendingDatabaseChange, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKSyncEnginePendingZoneDelete;
);

unsafe impl Send for CKSyncEnginePendingZoneDelete {}

unsafe impl Sync for CKSyncEnginePendingZoneDelete {}

extern_conformance!(
    unsafe impl NSObjectProtocol for CKSyncEnginePendingZoneDelete {}
);

impl CKSyncEnginePendingZoneDelete {
    extern_methods!(
        #[cfg(feature = "CKRecordZoneID")]
        #[unsafe(method(initWithZoneID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithZoneID(
            this: Allocated<Self>,
            zone_id: &CKRecordZoneID,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `CKSyncEnginePendingDatabaseChange`.
impl CKSyncEnginePendingZoneDelete {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}