objc2_cloud_kit/generated/
CKRecord.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::*;
6#[cfg(feature = "objc2-core-location")]
7use objc2_core_location::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordtype?language=objc)
13pub type CKRecordType = NSString;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordfieldkey?language=objc)
16pub type CKRecordFieldKey = NSString;
17
18extern "C" {
19    /// Use this constant for the recordType parameter when fetching User Records.
20    ///
21    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordtypeuserrecord?language=objc)
22    pub static CKRecordTypeUserRecord: &'static CKRecordType;
23}
24
25extern "C" {
26    /// For use in queries to match on record properties.  Matches `record.recordID`.  Value is a `CKRecordID`
27    ///
28    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordrecordidkey?language=objc)
29    pub static CKRecordRecordIDKey: &'static CKRecordFieldKey;
30}
31
32extern "C" {
33    /// For use in queries to match on record properties.  Matches `record.creatorUserRecordID`.  Value is a `CKRecordID`
34    ///
35    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordcreatoruserrecordidkey?language=objc)
36    pub static CKRecordCreatorUserRecordIDKey: &'static CKRecordFieldKey;
37}
38
39extern "C" {
40    /// For use in queries to match on record properties.  Matches `record.creationDate`.  Value is a `NSDate`
41    ///
42    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordcreationdatekey?language=objc)
43    pub static CKRecordCreationDateKey: &'static CKRecordFieldKey;
44}
45
46extern "C" {
47    /// For use in queries to match on record properties.  Matches `record.lastModifiedUserRecordID`.  Value is a `CKRecordID`
48    ///
49    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordlastmodifieduserrecordidkey?language=objc)
50    pub static CKRecordLastModifiedUserRecordIDKey: &'static CKRecordFieldKey;
51}
52
53extern "C" {
54    /// For use in queries to match on record properties.  Matches `record.modificationDate`.  Value is a `NSDate`
55    ///
56    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordmodificationdatekey?language=objc)
57    pub static CKRecordModificationDateKey: &'static CKRecordFieldKey;
58}
59
60extern "C" {
61    /// For use in queries to match on record properties.  Matches `record.parent`
62    ///
63    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordparentkey?language=objc)
64    pub static CKRecordParentKey: &'static CKRecordFieldKey;
65}
66
67extern "C" {
68    /// For use in queries to match on record properties.  Matches `record.share`
69    ///
70    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordsharekey?language=objc)
71    pub static CKRecordShareKey: &'static CKRecordFieldKey;
72}
73
74extern_protocol!(
75    /// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordvalue?language=objc)
76    pub unsafe trait CKRecordValue: NSObjectProtocol {}
77);
78
79extern_class!(
80    /// [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecord?language=objc)
81    #[unsafe(super(NSObject))]
82    #[derive(Debug, PartialEq, Eq, Hash)]
83    pub struct CKRecord;
84);
85
86extern_conformance!(
87    unsafe impl NSCoding for CKRecord {}
88);
89
90extern_conformance!(
91    unsafe impl NSCopying for CKRecord {}
92);
93
94unsafe impl CopyingHelper for CKRecord {
95    type Result = Self;
96}
97
98extern_conformance!(
99    unsafe impl NSObjectProtocol for CKRecord {}
100);
101
102extern_conformance!(
103    unsafe impl NSSecureCoding for CKRecord {}
104);
105
106impl CKRecord {
107    extern_methods!(
108        #[unsafe(method(init))]
109        #[unsafe(method_family = init)]
110        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
111
112        #[unsafe(method(new))]
113        #[unsafe(method_family = new)]
114        pub unsafe fn new() -> Retained<Self>;
115
116        /// This creates the record in the default zone.
117        #[unsafe(method(initWithRecordType:))]
118        #[unsafe(method_family = init)]
119        pub unsafe fn initWithRecordType(
120            this: Allocated<Self>,
121            record_type: &CKRecordType,
122        ) -> Retained<Self>;
123
124        #[cfg(feature = "CKRecordID")]
125        #[unsafe(method(initWithRecordType:recordID:))]
126        #[unsafe(method_family = init)]
127        pub unsafe fn initWithRecordType_recordID(
128            this: Allocated<Self>,
129            record_type: &CKRecordType,
130            record_id: &CKRecordID,
131        ) -> Retained<Self>;
132
133        #[cfg(feature = "CKRecordZoneID")]
134        #[unsafe(method(initWithRecordType:zoneID:))]
135        #[unsafe(method_family = init)]
136        pub unsafe fn initWithRecordType_zoneID(
137            this: Allocated<Self>,
138            record_type: &CKRecordType,
139            zone_id: &CKRecordZoneID,
140        ) -> Retained<Self>;
141
142        #[unsafe(method(recordType))]
143        #[unsafe(method_family = none)]
144        pub unsafe fn recordType(&self) -> Retained<CKRecordType>;
145
146        #[cfg(feature = "CKRecordID")]
147        #[unsafe(method(recordID))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn recordID(&self) -> Retained<CKRecordID>;
150
151        /// 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.
152        #[unsafe(method(recordChangeTag))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn recordChangeTag(&self) -> Option<Retained<NSString>>;
155
156        #[cfg(feature = "CKRecordID")]
157        /// This is a User Record recordID, identifying the user that created this record.
158        #[unsafe(method(creatorUserRecordID))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn creatorUserRecordID(&self) -> Option<Retained<CKRecordID>>;
161
162        #[unsafe(method(creationDate))]
163        #[unsafe(method_family = none)]
164        pub unsafe fn creationDate(&self) -> Option<Retained<NSDate>>;
165
166        #[cfg(feature = "CKRecordID")]
167        /// This is a User Record recordID, identifying the user that last modified this record.
168        #[unsafe(method(lastModifiedUserRecordID))]
169        #[unsafe(method_family = none)]
170        pub unsafe fn lastModifiedUserRecordID(&self) -> Option<Retained<CKRecordID>>;
171
172        #[unsafe(method(modificationDate))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn modificationDate(&self) -> Option<Retained<NSDate>>;
175
176        /// In addition to
177        /// `objectForKey:`and
178        /// `setObject:forKey:,`dictionary-style subscripting (
179        /// `record[key]`and
180        ///
181        /// ```text
182        ///  record[key] = value
183        /// ```
184        ///
185        /// ) can be used to get and set values.
186        /// Acceptable value object classes are:
187        /// - CKReference
188        /// - CKAsset
189        /// - CLLocation
190        /// - NSData
191        /// - NSDate
192        /// - NSNumber
193        /// - NSString
194        /// - NSArray containing objects of any of the types above
195        ///
196        /// Any other classes will result in an exception with name
197        /// `NSInvalidArgumentException.`
198        /// Whenever possible, value objects will be copied when set on a record.
199        ///
200        /// Field keys starting with '_' are reserved. Attempting to set a key prefixed with a '_' will result in an error.
201        ///
202        /// 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.
203        /// The maximum key length is 255 characters.
204        #[unsafe(method(objectForKey:))]
205        #[unsafe(method_family = none)]
206        pub unsafe fn objectForKey(
207            &self,
208            key: &CKRecordFieldKey,
209        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;
210
211        #[unsafe(method(setObject:forKey:))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn setObject_forKey(
214            &self,
215            object: Option<&ProtocolObject<dyn CKRecordValue>>,
216            key: &CKRecordFieldKey,
217        );
218
219        #[unsafe(method(allKeys))]
220        #[unsafe(method_family = none)]
221        pub unsafe fn allKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;
222
223        /// A special property that returns an array of token generated from all the string field values in the record.
224        ///
225        ///
226        /// These tokens have been normalized for the current locale, so they are suitable for performing full-text searches.
227        #[unsafe(method(allTokens))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn allTokens(&self) -> Retained<NSArray<NSString>>;
230
231        #[unsafe(method(objectForKeyedSubscript:))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn objectForKeyedSubscript(
234            &self,
235            key: &CKRecordFieldKey,
236        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;
237
238        #[unsafe(method(setObject:forKeyedSubscript:))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn setObject_forKeyedSubscript(
241            &self,
242            object: Option<&ProtocolObject<dyn CKRecordValue>>,
243            key: &CKRecordFieldKey,
244        );
245
246        /// A list of keys that have been modified on the local CKRecord instance
247        #[unsafe(method(changedKeys))]
248        #[unsafe(method_family = none)]
249        pub unsafe fn changedKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;
250
251        /// `CKRecord`supports
252        /// `NSSecureCoding.`When you invoke
253        /// `encodeWithCoder:`on a
254        /// `CKRecord,`it encodes all its values.  Including the record values you've set.
255        /// If you want to store a
256        /// `CKRecord`instance locally, AND you're already storing the record values locally, that's overkill.  In that case, you can use
257        /// `encodeSystemFieldsWithCoder:.`This will encode all parts of a
258        /// `CKRecord`except the record keys / values you have access to via the
259        /// `changedKeys`and
260        /// `objectForKey:`methods.
261        /// If you use
262        /// `initWithCoder:`to reconstitute a
263        /// `CKRecord`you encoded via
264        /// `encodeSystemFieldsWithCoder:,`then be aware that
265        /// - any record values you had set on the original instance, but had not saved, will be lost
266        /// - the reconstituted CKRecord's
267        /// `changedKeys`will be empty
268        #[unsafe(method(encodeSystemFieldsWithCoder:))]
269        #[unsafe(method_family = none)]
270        pub unsafe fn encodeSystemFieldsWithCoder(&self, coder: &NSCoder);
271
272        #[cfg(feature = "CKReference")]
273        /// The share property on a record can be set by creating a share using
274        ///
275        /// ```text
276        ///  -[CKShare initWithRootRecord:]
277        /// ```
278        ///
279        /// .
280        ///
281        /// 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.
282        ///
283        /// Sharing is only supported in zones with the
284        /// `CKRecordZoneCapabilitySharing`capability. The default zone does not support sharing.
285        ///
286        /// If any records have a parent reference to this record, they are implicitly shared alongside this record.
287        ///
288        /// 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
289        /// `CKErrorAlreadyShared`error if you try to share any of that record's parents.
290        ///
291        /// Child records can be shared independently, even if they have a common parent.  For example:
292        /// Record A has two child records, Record B and Record C.
293        /// A
294        /// /
295        /// \
296        /// B   C
297        ///
298        /// These configurations are supported:
299        /// - Record A part of Share 1, or
300        /// - Record B part of Share 1, or
301        /// - Record C part of Share 1, or
302        /// - Record B part of Share 1, Record C part of Share 2
303        ///
304        /// These configurations are not supported:
305        /// Record A part of Share 1, Record B part of Share 2, or
306        /// -- This is not allowed because Record B would then be in two shares; Share 1 by being Record A's child, and Share 2
307        /// Record A part of Share 1, Record C part of Share 2, or
308        /// -- This is not allowed because Record C would then be in two shares; Share 1 by being Record A's child, and Share 2
309        /// Record A part of Share 1, Record B part of Share 2, Record C part of Share 3
310        /// -- This is not allowed because both Record B and Record C would then each be in two shares.
311        ///
312        /// 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.
313        #[unsafe(method(share))]
314        #[unsafe(method_family = none)]
315        pub unsafe fn share(&self) -> Option<Retained<CKReference>>;
316
317        #[cfg(feature = "CKReference")]
318        /// Use a parent reference to teach CloudKit about the hierarchy of your records.
319        ///
320        ///
321        /// When a record is shared, all children of that record are also shared.
322        ///
323        /// A parent record reference must have
324        /// `CKReferenceActionNone`set. You can create a separate reference with
325        /// `CKReferenceActionDeleteSelf`if you would like your hierarchy cleaned up when the parent record is deleted.
326        ///
327        /// The target of a parent reference must exist at save time - either already on the server, or part of the same
328        /// `CKModifyRecordsOperation`batch.
329        ///
330        /// You are encouraged to set up the
331        /// `parent`relationships as part of normal record saves, even if you're not planning on sharing records at this time.
332        /// 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
333        /// `share`reference.
334        #[unsafe(method(parent))]
335        #[unsafe(method_family = none)]
336        pub unsafe fn parent(&self) -> Option<Retained<CKReference>>;
337
338        #[cfg(feature = "CKReference")]
339        /// Setter for [`parent`][Self::parent].
340        #[unsafe(method(setParent:))]
341        #[unsafe(method_family = none)]
342        pub unsafe fn setParent(&self, parent: Option<&CKReference>);
343
344        /// Convenience wrappers around creating a
345        /// `CKReference`to a parent record. The resulting
346        /// `CKReference`will have
347        ///
348        /// ```text
349        ///  referenceAction = CKReferenceActionNone
350        /// ```
351        #[unsafe(method(setParentReferenceFromRecord:))]
352        #[unsafe(method_family = none)]
353        pub unsafe fn setParentReferenceFromRecord(&self, parent_record: Option<&CKRecord>);
354
355        #[cfg(feature = "CKRecordID")]
356        #[unsafe(method(setParentReferenceFromRecordID:))]
357        #[unsafe(method_family = none)]
358        pub unsafe fn setParentReferenceFromRecordID(&self, parent_record_id: Option<&CKRecordID>);
359    );
360}
361
362extern_conformance!(
363    unsafe impl CKRecordValue for NSString {}
364);
365
366extern_conformance!(
367    unsafe impl CKRecordValue for NSNumber {}
368);
369
370extern_conformance!(
371    unsafe impl CKRecordValue for NSArray {}
372);
373
374extern_conformance!(
375    unsafe impl CKRecordValue for NSDate {}
376);
377
378extern_conformance!(
379    unsafe impl CKRecordValue for NSData {}
380);
381
382/// CKRecordValue.
383#[cfg(feature = "CKReference")]
384impl CKReference {
385    extern_methods!();
386}
387
388#[cfg(feature = "CKReference")]
389extern_conformance!(
390    unsafe impl CKRecordValue for CKReference {}
391);
392
393/// CKRecordValue.
394#[cfg(feature = "CKAsset")]
395impl CKAsset {
396    extern_methods!();
397}
398
399#[cfg(feature = "CKAsset")]
400extern_conformance!(
401    unsafe impl CKRecordValue for CKAsset {}
402);
403
404#[cfg(feature = "objc2-core-location")]
405extern_conformance!(
406    unsafe impl CKRecordValue for CLLocation {}
407);
408
409extern_protocol!(
410    /// Formalizes a protocol for getting and setting keys on a CKRecord.  Not intended to be used directly by client code
411    ///
412    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckrecordkeyvaluesetting?language=objc)
413    pub unsafe trait CKRecordKeyValueSetting: NSObjectProtocol {
414        #[unsafe(method(objectForKey:))]
415        #[unsafe(method_family = none)]
416        unsafe fn objectForKey(
417            &self,
418            key: &CKRecordFieldKey,
419        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;
420
421        #[unsafe(method(setObject:forKey:))]
422        #[unsafe(method_family = none)]
423        unsafe fn setObject_forKey(
424            &self,
425            object: Option<&ProtocolObject<dyn CKRecordValue>>,
426            key: &CKRecordFieldKey,
427        );
428
429        #[unsafe(method(objectForKeyedSubscript:))]
430        #[unsafe(method_family = none)]
431        unsafe fn objectForKeyedSubscript(
432            &self,
433            key: &CKRecordFieldKey,
434        ) -> Option<Retained<ProtocolObject<dyn CKRecordValue>>>;
435
436        #[unsafe(method(setObject:forKeyedSubscript:))]
437        #[unsafe(method_family = none)]
438        unsafe fn setObject_forKeyedSubscript(
439            &self,
440            object: Option<&ProtocolObject<dyn CKRecordValue>>,
441            key: &CKRecordFieldKey,
442        );
443
444        #[unsafe(method(allKeys))]
445        #[unsafe(method_family = none)]
446        unsafe fn allKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;
447
448        #[unsafe(method(changedKeys))]
449        #[unsafe(method_family = none)]
450        unsafe fn changedKeys(&self) -> Retained<NSArray<CKRecordFieldKey>>;
451    }
452);
453
454/// CKRecordKeyValueSettingConformance.
455impl CKRecord {
456    extern_methods!(
457        /// 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.
458        /// 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.
459        /// All CKRecordValue types can be set here except CKAsset and CKReference.
460        #[unsafe(method(encryptedValues))]
461        #[unsafe(method_family = none)]
462        pub unsafe fn encryptedValues(
463            &self,
464        ) -> Retained<ProtocolObject<dyn CKRecordKeyValueSetting>>;
465    );
466}
467
468extern_conformance!(
469    unsafe impl CKRecordKeyValueSetting for CKRecord {}
470);