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
//! 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::*;

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

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

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

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

        /// This defines per-operation configuration settings.
        ///
        ///
        /// See the CKOperationConfiguration class description for info on how this configuration composes with CKOperationGroup.defaultConfiguration
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(configuration))]
        #[unsafe(method_family = none)]
        pub unsafe fn configuration(&self) -> Retained<CKOperationConfiguration>;

        /// Setter for [`configuration`][Self::configuration].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setConfiguration:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setConfiguration(&self, configuration: Option<&CKOperationConfiguration>);

        #[cfg(feature = "CKOperationGroup")]
        /// The group this operation is associated with
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(group))]
        #[unsafe(method_family = none)]
        pub unsafe fn group(&self) -> Option<Retained<CKOperationGroup>>;

        #[cfg(feature = "CKOperationGroup")]
        /// Setter for [`group`][Self::group].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setGroup:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setGroup(&self, group: Option<&CKOperationGroup>);

        /// This is an identifier unique to this CKOperation.
        ///
        ///
        /// This value is chosen by the system, and will be unique to this instance of a CKOperation.  This identifier will be sent to Apple's servers, and can be used to identify any server-side logging associated with this operation.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(operationID))]
        #[unsafe(method_family = none)]
        pub unsafe fn operationID(&self) -> Retained<CKOperationID>;

        #[cfg(feature = "block2")]
        /// This callback is called after a long lived operation has begun running and is persisted.
        ///
        ///
        /// Once this callback is called the operation will continue running even if the current process exits.
        /// Each
        /// `CKOperation`instance has a private serial queue. This queue is used for all callback block invocations.
        /// This block may share mutable state with other blocks assigned to this operation, but any such mutable state
        /// should not be concurrently used outside of blocks assigned to this operation.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(longLivedOperationWasPersistedBlock))]
        #[unsafe(method_family = none)]
        pub unsafe fn longLivedOperationWasPersistedBlock(&self)
            -> *mut block2::DynBlock<dyn Fn()>;

        #[cfg(feature = "block2")]
        /// Setter for [`longLivedOperationWasPersistedBlock`][Self::longLivedOperationWasPersistedBlock].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setLongLivedOperationWasPersistedBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLongLivedOperationWasPersistedBlock(
            &self,
            long_lived_operation_was_persisted_block: Option<&block2::DynBlock<dyn Fn()>>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl CKOperation {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// An operation configuration is a set of properties that describes how your operation should behave.  All properties have a default value.  When determining what properties to apply to an operation, we consult the operation's configuration property, as well as the operation->group->defaultConfiguration property.  We combine them following these rules:
    ///
    /// ```text
    ///    Group Default Configuration Value | Operation Configuration Value |        Value Applied To Operation
    ///   -----------------------------------+-------------------------------+-----------------------------------------
    ///              default value           |         default value         |                  default value
    ///              default value           |         explicit value        |       operation.configuration explicit value
    ///              explicit value          |         default value         | operation.group.defaultConfiguration explicit value
    ///              explicit value          |         explicit value        |       operation.configuration explicit value
    /// ```
    ///
    /// For example:
    /// CKOperationGroup -> defaultConfiguration -> allowsCellularAccess explicitly set to NO
    /// + CKOperation -> configuration -> allowsCellularAccess has default value of YES
    /// = disallow cellular access
    ///
    /// CKOperationGroup -> defaultConfiguration -> allowsCellularAccess explicitly set to NO
    /// + CKOperation -> configuration -> allowsCellularAccess explicitly set to YES
    /// = allow cellular access
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cloudkit/ckoperationconfiguration?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CKOperationConfiguration;
);

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

impl CKOperationConfiguration {
    extern_methods!(
        #[cfg(feature = "CKContainer")]
        /// If no container is set, [CKContainer defaultContainer] is used
        #[unsafe(method(container))]
        #[unsafe(method_family = none)]
        pub unsafe fn container(&self) -> Option<Retained<CKContainer>>;

        #[cfg(feature = "CKContainer")]
        /// Setter for [`container`][Self::container].
        #[unsafe(method(setContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setContainer(&self, container: Option<&CKContainer>);

        /// CKOperations behave differently depending on how you set qualityOfService.
        ///
        ///
        /// ```text
        ///   Quality of Service | timeoutIntervalForResource | Network Error Behavior | Discretionary Behavior
        ///   -------------------+----------------------------+------------------------+-----------------------
        ///   UserInteractive    | -1 (no enforcement)        | fail                   | nonDiscretionary
        ///   UserInitiated      | -1 (no enforcement)        | fail                   | nonDiscretionary
        ///   Default            | 1 week                     | fail                   | discretionary when app backgrounded
        ///   Utility            | 1 week                     | internally retried     | discretionary when app backgrounded
        ///   Background         | 1 week                     | internally retried     | discretionary
        /// ```
        ///
        /// timeoutIntervalForResource
        /// - the timeout interval for any network resources retrieved by this operation
        /// - this can be overridden via CKOperationConfiguration's timeoutIntervalForResource property
        ///
        /// Network Error Behavior
        /// - when a network request in service of a CKOperation fails due to a networking error, the operation may fail with that error, or internally retry the network request.  Only a subset of networking errors are retried, and limiting factors such as timeoutIntervalForResource are still applicable.
        ///
        /// Discretionary Behavior
        /// - network requests in service of a CKOperation may be marked as discretionary
        /// - discretionary network requests are scheduled at the description of the system for optimal performance
        ///
        /// CKOperations have a default qualityOfService of Default.
        #[unsafe(method(qualityOfService))]
        #[unsafe(method_family = none)]
        pub unsafe fn qualityOfService(&self) -> NSQualityOfService;

        /// Setter for [`qualityOfService`][Self::qualityOfService].
        #[unsafe(method(setQualityOfService:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setQualityOfService(&self, quality_of_service: NSQualityOfService);

        /// Defaults to
        /// `YES`
        #[unsafe(method(allowsCellularAccess))]
        #[unsafe(method_family = none)]
        pub unsafe fn allowsCellularAccess(&self) -> bool;

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

        /// Long lived operations will continue running even if your process exits. If your process remains alive for the lifetime of the long lived operation its behavior is the same as a regular operation.
        ///
        /// Long lived operations can be fetched and replayed from the container via the
        /// `fetchAllLongLivedOperations:`and
        /// `fetchLongLivedOperationsWithIDs:`APIs. Your code should only fetch and re-enqueue long lived operations on app launch.
        ///
        /// Long lived operations persist until their -[NSOperation completionBlock] returns or until the operation is cancelled.
        /// Long lived operations may be garbage collected 24 hours after they finish running if no client has replayed them.
        ///
        /// The default value for longLived is NO. Changing the value of longLived on an already started operation or on an outstanding long lived operation fetched from CKContainer has no effect.
        #[unsafe(method(isLongLived))]
        #[unsafe(method_family = none)]
        pub unsafe fn isLongLived(&self) -> bool;

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

        /// If non-zero, overrides the timeout interval for any network requests issued by this operation.
        /// The default value is 60.
        ///
        ///
        /// See: NSURLSessionConfiguration.timeoutIntervalForRequest
        #[unsafe(method(timeoutIntervalForRequest))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeoutIntervalForRequest(&self) -> NSTimeInterval;

        /// Setter for [`timeoutIntervalForRequest`][Self::timeoutIntervalForRequest].
        #[unsafe(method(setTimeoutIntervalForRequest:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTimeoutIntervalForRequest(
            &self,
            timeout_interval_for_request: NSTimeInterval,
        );

        /// If set, overrides the timeout interval for any network resources retrieved by this operation.
        /// If not explicitly set, defaults to a value based on the operation's
        /// `qualityOfService`
        ///
        /// See: NSURLSessionConfiguration.timeoutIntervalForResource
        #[unsafe(method(timeoutIntervalForResource))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeoutIntervalForResource(&self) -> NSTimeInterval;

        /// Setter for [`timeoutIntervalForResource`][Self::timeoutIntervalForResource].
        #[unsafe(method(setTimeoutIntervalForResource:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTimeoutIntervalForResource(
            &self,
            timeout_interval_for_resource: NSTimeInterval,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl CKOperationConfiguration {
    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>;
    );
}

/// CKOperationDeprecated.
///
/// These deprecated properties now read and write from the CKOperation's configuration
impl CKOperation {
    extern_methods!(
        #[cfg(feature = "CKContainer")]
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(container))]
        #[unsafe(method_family = none)]
        pub unsafe fn container(&self) -> Option<Retained<CKContainer>>;

        #[cfg(feature = "CKContainer")]
        /// Setter for [`container`][Self::container].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(setContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setContainer(&self, container: Option<&CKContainer>);

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(allowsCellularAccess))]
        #[unsafe(method_family = none)]
        pub unsafe fn allowsCellularAccess(&self) -> bool;

        /// Setter for [`allowsCellularAccess`][Self::allowsCellularAccess].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(setAllowsCellularAccess:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAllowsCellularAccess(&self, allows_cellular_access: bool);

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(isLongLived))]
        #[unsafe(method_family = none)]
        pub unsafe fn isLongLived(&self) -> bool;

        /// Setter for [`isLongLived`][Self::isLongLived].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(setLongLived:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLongLived(&self, long_lived: bool);

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(timeoutIntervalForRequest))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeoutIntervalForRequest(&self) -> NSTimeInterval;

        /// Setter for [`timeoutIntervalForRequest`][Self::timeoutIntervalForRequest].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(setTimeoutIntervalForRequest:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTimeoutIntervalForRequest(
            &self,
            timeout_interval_for_request: NSTimeInterval,
        );

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(timeoutIntervalForResource))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeoutIntervalForResource(&self) -> NSTimeInterval;

        /// Setter for [`timeoutIntervalForResource`][Self::timeoutIntervalForResource].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "Use CKOperationConfiguration"]
        #[unsafe(method(setTimeoutIntervalForResource:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTimeoutIntervalForResource(
            &self,
            timeout_interval_for_resource: NSTimeInterval,
        );
    );
}