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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//! 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::*;
#[cfg(feature = "objc2-core-location")]
use objc2_core_location::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordtype?language=objc)
pub type CKRecordType = NSString;

/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordfieldkey?language=objc)
pub type CKRecordFieldKey = NSString;

extern "C" {
    /// Use this constant for the recordType parameter when fetching User Records.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordtypeuserrecord?language=objc)
    pub static CKRecordTypeUserRecord: &'static CKRecordType;
}

extern "C" {
    /// For use in queries to match on record properties.  Matches `record.recordID`.  Value is a ``CKRecordID``
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordrecordidkey?language=objc)
    pub static CKRecordRecordIDKey: &'static CKRecordFieldKey;
}

extern "C" {
    /// For use in queries to match on record properties.  Matches `record.creatorUserRecordID`.  Value is a ``CKRecordID``
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordcreatoruserrecordidkey?language=objc)
    pub static CKRecordCreatorUserRecordIDKey: &'static CKRecordFieldKey;
}

extern "C" {
    /// For use in queries to match on record properties.  Matches `record.creationDate`.  Value is a `NSDate`
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordcreationdatekey?language=objc)
    pub static CKRecordCreationDateKey: &'static CKRecordFieldKey;
}

extern "C" {
    /// For use in queries to match on record properties.  Matches `record.lastModifiedUserRecordID`.  Value is a ``CKRecordID``
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordlastmodifieduserrecordidkey?language=objc)
    pub static CKRecordLastModifiedUserRecordIDKey: &'static CKRecordFieldKey;
}

extern "C" {
    /// For use in queries to match on record properties.  Matches `record.modificationDate`.  Value is a `NSDate`
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordmodificationdatekey?language=objc)
    pub static CKRecordModificationDateKey: &'static CKRecordFieldKey;
}

extern "C" {
    /// For use in queries to match on record properties.  Matches `record.parent`
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordparentkey?language=objc)
    pub static CKRecordParentKey: &'static CKRecordFieldKey;
}

extern "C" {
    /// For use in queries to match on record properties.  Matches `record.share`
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordsharekey?language=objc)
    pub static CKRecordShareKey: &'static CKRecordFieldKey;
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordvalue?language=objc)
    pub unsafe trait CKRecordValue: NSObjectProtocol {}
);

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecord?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKRecord;
);

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

extern_conformance!(
    unsafe impl NSCopying for CKRecord {}
);

unsafe impl CopyingHelper for CKRecord {
    type Result = Self;
}

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

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

impl CKRecord {
    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>;

        /// This creates the record in the default zone.
        #[unsafe(method(initWithRecordType:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithRecordType(
            this: Allocated<Self>,
            record_type: &CKRecordType,
        ) -> Retained<Self>;

        #[cfg(feature = "CKRecordID")]
        #[unsafe(method(initWithRecordType:recordID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithRecordType_recordID(
            this: Allocated<Self>,
            record_type: &CKRecordType,
            record_id: &CKRecordID,
        ) -> Retained<Self>;

        #[cfg(feature = "CKRecordZoneID")]
        #[unsafe(method(initWithRecordType:zoneID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithRecordType_zoneID(
            this: Allocated<Self>,
            record_type: &CKRecordType,
            zone_id: &CKRecordZoneID,
        ) -> Retained<Self>;

        #[unsafe(method(recordType))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordType(&self) -> Retained<CKRecordType>;

        #[cfg(feature = "CKRecordID")]
        #[unsafe(method(recordID))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordID(&self) -> Retained<CKRecordID>;

        /// Change tags are updated by the server to a unique value every time a record is modified.  A different change tag necessarily means that the contents of the record are different.
        #[unsafe(method(recordChangeTag))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordChangeTag(&self) -> Option<Retained<NSString>>;

        #[cfg(feature = "CKRecordID")]
        /// This is a User Record recordID, identifying the user that created this record.
        #[unsafe(method(creatorUserRecordID))]
        #[unsafe(method_family = none)]
        pub unsafe fn creatorUserRecordID(&self) -> Option<Retained<CKRecordID>>;

        #[unsafe(method(creationDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn creationDate(&self) -> Option<Retained<NSDate>>;

        #[cfg(feature = "CKRecordID")]
        /// This is a User Record recordID, identifying the user that last modified this record.
        #[unsafe(method(lastModifiedUserRecordID))]
        #[unsafe(method_family = none)]
        pub unsafe fn lastModifiedUserRecordID(&self) -> Option<Retained<CKRecordID>>;

        #[unsafe(method(modificationDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn modificationDate(&self) -> Option<Retained<NSDate>>;

        /// In addition to
        /// `objectForKey:`and
        /// `setObject:forKey:,`dictionary-style subscripting (
        /// `record[key]`and
        ///
        /// ```text
        ///  record[key] = value
        /// ```
        ///
        /// ) can be used to get and set values.
        /// Acceptable value object classes are:
        /// - CKReference
        /// - CKAsset
        /// - CLLocation
        /// - NSData
        /// - NSDate
        /// - NSNumber
        /// - NSString
        /// - NSArray containing objects of any of the types above
        ///
        /// Any other classes will result in an exception with name
        /// `NSInvalidArgumentException.`
        /// Whenever possible, value objects will be copied when set on a record.
        ///
        /// Field keys starting with '_' are reserved. Attempting to set a key prefixed with a '_' will result in an error.
        ///
        /// Key names roughly match C variable name restrictions. They must begin with an ASCII letter and can contain ASCII letters and numbers and the underscore character.
        /// The maximum key length is 255 characters.
        #[unsafe(method(objectForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn objectForKey(
            &self,
            key: &CKRecordFieldKey,
        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;

        #[unsafe(method(setObject:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setObject_forKey(
            &self,
            object: Option<&ProtocolObject<dyn CKRecordValue>>,
            key: &CKRecordFieldKey,
        );

        #[unsafe(method(allKeys))]
        #[unsafe(method_family = none)]
        pub unsafe fn allKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;

        /// A special property that returns an array of token generated from all the string field values in the record.
        ///
        ///
        /// These tokens have been normalized for the current locale, so they are suitable for performing full-text searches.
        #[unsafe(method(allTokens))]
        #[unsafe(method_family = none)]
        pub unsafe fn allTokens(&self) -> Retained<NSArray<NSString>>;

        #[unsafe(method(objectForKeyedSubscript:))]
        #[unsafe(method_family = none)]
        pub unsafe fn objectForKeyedSubscript(
            &self,
            key: &CKRecordFieldKey,
        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;

        #[unsafe(method(setObject:forKeyedSubscript:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setObject_forKeyedSubscript(
            &self,
            object: Option<&ProtocolObject<dyn CKRecordValue>>,
            key: &CKRecordFieldKey,
        );

        /// A list of keys that have been modified on the local CKRecord instance
        #[unsafe(method(changedKeys))]
        #[unsafe(method_family = none)]
        pub unsafe fn changedKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;

        /// `CKRecord`supports
        /// `NSSecureCoding.`When you invoke
        /// `encodeWithCoder:`on a
        /// `CKRecord,`it encodes all its values.  Including the record values you've set.
        /// If you want to store a
        /// `CKRecord`instance locally, AND you're already storing the record values locally, that's overkill.  In that case, you can use
        /// `encodeSystemFieldsWithCoder:.`This will encode all parts of a
        /// `CKRecord`except the record keys / values you have access to via the
        /// `changedKeys`and
        /// `objectForKey:`methods.
        /// If you use
        /// `initWithCoder:`to reconstitute a
        /// `CKRecord`you encoded via
        /// `encodeSystemFieldsWithCoder:,`then be aware that
        /// - any record values you had set on the original instance, but had not saved, will be lost
        /// - the reconstituted CKRecord's
        /// `changedKeys`will be empty
        ///
        /// # Safety
        ///
        /// `coder` possibly has further requirements.
        #[unsafe(method(encodeSystemFieldsWithCoder:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeSystemFieldsWithCoder(&self, coder: &NSCoder);

        #[cfg(feature = "CKReference")]
        /// The share property on a record can be set by creating a share using
        ///
        /// ```text
        ///  -[CKShare initWithRootRecord:]
        /// ```
        ///
        /// .
        ///
        /// The share property on a record will be removed when the corresponding CKShare is deleted from the server. Send this record in the same batch as the share delete and this record's share property will be updated.
        ///
        /// Sharing is only supported in zones with the
        /// `CKRecordZoneCapabilitySharing`capability. The default zone does not support sharing.
        ///
        /// If any records have a parent reference to this record, they are implicitly shared alongside this record.
        ///
        /// Note that records in a parent chain must only exist within one share. If a child record already has a share reference set then you will get a
        /// `CKErrorAlreadyShared`error if you try to share any of that record's parents.
        ///
        /// Child records can be shared independently, even if they have a common parent.  For example:
        /// Record A has two child records, Record B and Record C.
        /// A
        /// /
        /// \
        /// B   C
        ///
        /// These configurations are supported:
        /// - Record A part of Share 1, or
        /// - Record B part of Share 1, or
        /// - Record C part of Share 1, or
        /// - Record B part of Share 1, Record C part of Share 2
        ///
        /// These configurations are not supported:
        /// Record A part of Share 1, Record B part of Share 2, or
        /// -- This is not allowed because Record B would then be in two shares; Share 1 by being Record A's child, and Share 2
        /// Record A part of Share 1, Record C part of Share 2, or
        /// -- This is not allowed because Record C would then be in two shares; Share 1 by being Record A's child, and Share 2
        /// Record A part of Share 1, Record B part of Share 2, Record C part of Share 3
        /// -- This is not allowed because both Record B and Record C would then each be in two shares.
        ///
        /// Whenever possible, it is suggested that you construct your parent hierarchies such that you will only need to share the topmost record of that hierarchy.
        #[unsafe(method(share))]
        #[unsafe(method_family = none)]
        pub unsafe fn share(&self) -> Option<Retained<CKReference>>;

        #[cfg(feature = "CKReference")]
        /// Use a parent reference to teach CloudKit about the hierarchy of your records.
        ///
        ///
        /// When a record is shared, all children of that record are also shared.
        ///
        /// A parent record reference must have
        /// `CKReferenceActionNone`set. You can create a separate reference with
        /// `CKReferenceActionDeleteSelf`if you would like your hierarchy cleaned up when the parent record is deleted.
        ///
        /// The target of a parent reference must exist at save time - either already on the server, or part of the same
        /// `CKModifyRecordsOperation`batch.
        ///
        /// You are encouraged to set up the
        /// `parent`relationships as part of normal record saves, even if you're not planning on sharing records at this time.
        /// This allows you to share and unshare a hierarchy of records at a later date by only modifying the "top level" record, setting or clearing its
        /// `share`reference.
        #[unsafe(method(parent))]
        #[unsafe(method_family = none)]
        pub unsafe fn parent(&self) -> Option<Retained<CKReference>>;

        #[cfg(feature = "CKReference")]
        /// Setter for [`parent`][Self::parent].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setParent:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setParent(&self, parent: Option<&CKReference>);

        /// Convenience wrappers around creating a
        /// `CKReference`to a parent record. The resulting
        /// `CKReference`will have
        ///
        /// ```text
        ///  referenceAction = CKReferenceActionNone
        /// ```
        #[unsafe(method(setParentReferenceFromRecord:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setParentReferenceFromRecord(&self, parent_record: Option<&CKRecord>);

        #[cfg(feature = "CKRecordID")]
        #[unsafe(method(setParentReferenceFromRecordID:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setParentReferenceFromRecordID(&self, parent_record_id: Option<&CKRecordID>);
    );
}

extern_conformance!(
    unsafe impl CKRecordValue for NSString {}
);

extern_conformance!(
    unsafe impl CKRecordValue for NSNumber {}
);

extern_conformance!(
    unsafe impl CKRecordValue for NSArray {}
);

extern_conformance!(
    unsafe impl CKRecordValue for NSDate {}
);

extern_conformance!(
    unsafe impl CKRecordValue for NSData {}
);

/// CKRecordValue.
#[cfg(feature = "CKReference")]
impl CKReference {
    extern_methods!();
}

#[cfg(feature = "CKReference")]
extern_conformance!(
    unsafe impl CKRecordValue for CKReference {}
);

/// CKRecordValue.
#[cfg(feature = "CKAsset")]
impl CKAsset {
    extern_methods!();
}

#[cfg(feature = "CKAsset")]
extern_conformance!(
    unsafe impl CKRecordValue for CKAsset {}
);

#[cfg(feature = "objc2-core-location")]
extern_conformance!(
    unsafe impl CKRecordValue for CLLocation {}
);

extern_protocol!(
    /// Formalizes a protocol for getting and setting keys on a CKRecord.  Not intended to be used directly by client code
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordkeyvaluesetting?language=objc)
    pub unsafe trait CKRecordKeyValueSetting: NSObjectProtocol {
        #[unsafe(method(objectForKey:))]
        #[unsafe(method_family = none)]
        unsafe fn objectForKey(
            &self,
            key: &CKRecordFieldKey,
        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;

        #[unsafe(method(setObject:forKey:))]
        #[unsafe(method_family = none)]
        unsafe fn setObject_forKey(
            &self,
            object: Option<&ProtocolObject<dyn CKRecordValue>>,
            key: &CKRecordFieldKey,
        );

        #[unsafe(method(objectForKeyedSubscript:))]
        #[unsafe(method_family = none)]
        unsafe fn objectForKeyedSubscript(
            &self,
            key: &CKRecordFieldKey,
        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;

        #[unsafe(method(setObject:forKeyedSubscript:))]
        #[unsafe(method_family = none)]
        unsafe fn setObject_forKeyedSubscript(
            &self,
            object: Option<&ProtocolObject<dyn CKRecordValue>>,
            key: &CKRecordFieldKey,
        );

        #[unsafe(method(allKeys))]
        #[unsafe(method_family = none)]
        unsafe fn allKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;

        #[unsafe(method(changedKeys))]
        #[unsafe(method_family = none)]
        unsafe fn changedKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;
    }
);

/// CKRecordKeyValueSettingConformance.
impl CKRecord {
    extern_methods!(
        /// Any values set here will be locally encrypted before being saved to the server and locally decrypted when fetched from the server. Encryption and decryption is handled by the CloudKit framework.
        /// Key material necessary for decryption are available to the owner of the record, as well as any users that can access this record via a CKShare.
        /// All CKRecordValue types can be set here except CKAsset and CKReference.
        #[unsafe(method(encryptedValues))]
        #[unsafe(method_family = none)]
        pub unsafe fn encryptedValues(
            &self,
        ) -> Retained<ProtocolObject<dyn CKRecordKeyValueSetting>>;
    );
}

extern_conformance!(
    unsafe impl CKRecordKeyValueSetting for CKRecord {}
);