objc2-core-data 0.3.2

Bindings to the CoreData 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
//! 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/coredata/nsfetchrequestresulttype?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSFetchRequestResultType(pub NSUInteger);
bitflags::bitflags! {
    impl NSFetchRequestResultType: NSUInteger {
        #[doc(alias = "NSManagedObjectResultType")]
        const ManagedObjectResultType = 0x00;
        #[doc(alias = "NSManagedObjectIDResultType")]
        const ManagedObjectIDResultType = 0x01;
        #[doc(alias = "NSDictionaryResultType")]
        const DictionaryResultType = 0x02;
        #[doc(alias = "NSCountResultType")]
        const CountResultType = 0x04;
    }
}

unsafe impl Encode for NSFetchRequestResultType {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

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

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

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

extern_conformance!(
    unsafe impl NSFetchRequestResult for NSDictionary {}
);

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

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

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

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

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/coredata/nsfetchrequest?language=objc)
    #[unsafe(super(NSPersistentStoreRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "NSPersistentStoreRequest")]
    pub struct NSFetchRequest<ResultType: ?Sized = AnyObject>;
);

#[cfg(feature = "NSPersistentStoreRequest")]
impl<ResultType: ?Sized + Message + NSFetchRequestResult> NSFetchRequest<ResultType> {
    /// Unchecked conversion of the generic parameter.
    ///
    /// # Safety
    ///
    /// The generic must be valid to reinterpret as the given type.
    #[inline]
    pub unsafe fn cast_unchecked<NewResultType: ?Sized + Message + NSFetchRequestResult>(
        &self,
    ) -> &NSFetchRequest<NewResultType> {
        unsafe { &*((self as *const Self).cast()) }
    }
}

#[cfg(feature = "NSPersistentStoreRequest")]
extern_conformance!(
    unsafe impl<ResultType: ?Sized + NSCoding + NSFetchRequestResult> NSCoding
        for NSFetchRequest<ResultType>
    {
    }
);

#[cfg(feature = "NSPersistentStoreRequest")]
extern_conformance!(
    unsafe impl<ResultType: ?Sized + NSFetchRequestResult> NSCopying for NSFetchRequest<ResultType> {}
);

#[cfg(feature = "NSPersistentStoreRequest")]
unsafe impl<ResultType: ?Sized + Message + NSFetchRequestResult> CopyingHelper
    for NSFetchRequest<ResultType>
{
    type Result = Self;
}

#[cfg(feature = "NSPersistentStoreRequest")]
extern_conformance!(
    unsafe impl<ResultType: ?Sized + NSFetchRequestResult> NSObjectProtocol
        for NSFetchRequest<ResultType>
    {
    }
);

#[cfg(feature = "NSPersistentStoreRequest")]
impl<ResultType: Message + NSFetchRequestResult> NSFetchRequest<ResultType> {
    extern_methods!(
        #[unsafe(method(fetchRequestWithEntityName:))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchRequestWithEntityName(entity_name: &NSString) -> Retained<Self>;

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

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

        #[unsafe(method(execute:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn execute(&self) -> Result<Retained<NSArray<ResultType>>, Retained<NSError>>;

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

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

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

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

        /// Setter for [`predicate`][Self::predicate].
        #[unsafe(method(setPredicate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPredicate(&self, predicate: Option<&NSPredicate>);

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

        /// Setter for [`sortDescriptors`][Self::sortDescriptors].
        #[unsafe(method(setSortDescriptors:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSortDescriptors(
            &self,
            sort_descriptors: Option<&NSArray<NSSortDescriptor>>,
        );

        #[unsafe(method(fetchLimit))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchLimit(&self) -> NSUInteger;

        /// Setter for [`fetchLimit`][Self::fetchLimit].
        #[unsafe(method(setFetchLimit:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFetchLimit(&self, fetch_limit: NSUInteger);

        #[cfg(feature = "NSPersistentStore")]
        #[unsafe(method(affectedStores))]
        #[unsafe(method_family = none)]
        pub unsafe fn affectedStores(&self) -> Option<Retained<NSArray<NSPersistentStore>>>;

        #[cfg(feature = "NSPersistentStore")]
        /// Setter for [`affectedStores`][Self::affectedStores].
        #[unsafe(method(setAffectedStores:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAffectedStores(
            &self,
            affected_stores: Option<&NSArray<NSPersistentStore>>,
        );

        #[unsafe(method(resultType))]
        #[unsafe(method_family = none)]
        pub unsafe fn resultType(&self) -> NSFetchRequestResultType;

        /// Setter for [`resultType`][Self::resultType].
        #[unsafe(method(setResultType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setResultType(&self, result_type: NSFetchRequestResultType);

        #[unsafe(method(includesSubentities))]
        #[unsafe(method_family = none)]
        pub unsafe fn includesSubentities(&self) -> bool;

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

        #[unsafe(method(includesPropertyValues))]
        #[unsafe(method_family = none)]
        pub unsafe fn includesPropertyValues(&self) -> bool;

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

        #[unsafe(method(returnsObjectsAsFaults))]
        #[unsafe(method_family = none)]
        pub unsafe fn returnsObjectsAsFaults(&self) -> bool;

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

        #[unsafe(method(relationshipKeyPathsForPrefetching))]
        #[unsafe(method_family = none)]
        pub unsafe fn relationshipKeyPathsForPrefetching(
            &self,
        ) -> Option<Retained<NSArray<NSString>>>;

        /// Setter for [`relationshipKeyPathsForPrefetching`][Self::relationshipKeyPathsForPrefetching].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setRelationshipKeyPathsForPrefetching:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRelationshipKeyPathsForPrefetching(
            &self,
            relationship_key_paths_for_prefetching: Option<&NSArray<NSString>>,
        );

        #[unsafe(method(includesPendingChanges))]
        #[unsafe(method_family = none)]
        pub unsafe fn includesPendingChanges(&self) -> bool;

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

        #[unsafe(method(returnsDistinctResults))]
        #[unsafe(method_family = none)]
        pub unsafe fn returnsDistinctResults(&self) -> bool;

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

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

        /// Setter for [`propertiesToFetch`][Self::propertiesToFetch].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `properties_to_fetch` generic should be of the correct type.
        #[unsafe(method(setPropertiesToFetch:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPropertiesToFetch(&self, properties_to_fetch: Option<&NSArray>);

        #[unsafe(method(fetchOffset))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchOffset(&self) -> NSUInteger;

        /// Setter for [`fetchOffset`][Self::fetchOffset].
        #[unsafe(method(setFetchOffset:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFetchOffset(&self, fetch_offset: NSUInteger);

        #[unsafe(method(fetchBatchSize))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchBatchSize(&self) -> NSUInteger;

        /// Setter for [`fetchBatchSize`][Self::fetchBatchSize].
        #[unsafe(method(setFetchBatchSize:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFetchBatchSize(&self, fetch_batch_size: NSUInteger);

        #[unsafe(method(shouldRefreshRefetchedObjects))]
        #[unsafe(method_family = none)]
        pub unsafe fn shouldRefreshRefetchedObjects(&self) -> bool;

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

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

        /// Setter for [`propertiesToGroupBy`][Self::propertiesToGroupBy].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `properties_to_group_by` generic should be of the correct type.
        #[unsafe(method(setPropertiesToGroupBy:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPropertiesToGroupBy(&self, properties_to_group_by: Option<&NSArray>);

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

        /// Setter for [`havingPredicate`][Self::havingPredicate].
        #[unsafe(method(setHavingPredicate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHavingPredicate(&self, having_predicate: Option<&NSPredicate>);
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "NSPersistentStoreRequest")]
impl<ResultType: Message + NSFetchRequestResult> NSFetchRequest<ResultType> {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/coredata/nspersistentstoreasynchronousfetchresultcompletionblock?language=objc)
#[cfg(all(feature = "NSPersistentStoreResult", feature = "block2"))]
pub type NSPersistentStoreAsynchronousFetchResultCompletionBlock =
    *mut block2::DynBlock<dyn Fn(NonNull<NSAsynchronousFetchResult>)>;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/coredata/nsasynchronousfetchrequest?language=objc)
    #[unsafe(super(NSPersistentStoreRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "NSPersistentStoreRequest")]
    pub struct NSAsynchronousFetchRequest<ResultType: ?Sized = AnyObject>;
);

#[cfg(feature = "NSPersistentStoreRequest")]
impl<ResultType: ?Sized + Message + NSFetchRequestResult> NSAsynchronousFetchRequest<ResultType> {
    /// Unchecked conversion of the generic parameter.
    ///
    /// # Safety
    ///
    /// The generic must be valid to reinterpret as the given type.
    #[inline]
    pub unsafe fn cast_unchecked<NewResultType: ?Sized + Message + NSFetchRequestResult>(
        &self,
    ) -> &NSAsynchronousFetchRequest<NewResultType> {
        unsafe { &*((self as *const Self).cast()) }
    }
}

#[cfg(feature = "NSPersistentStoreRequest")]
extern_conformance!(
    unsafe impl<ResultType: ?Sized + NSFetchRequestResult> NSCopying
        for NSAsynchronousFetchRequest<ResultType>
    {
    }
);

#[cfg(feature = "NSPersistentStoreRequest")]
unsafe impl<ResultType: ?Sized + Message + NSFetchRequestResult> CopyingHelper
    for NSAsynchronousFetchRequest<ResultType>
{
    type Result = Self;
}

#[cfg(feature = "NSPersistentStoreRequest")]
extern_conformance!(
    unsafe impl<ResultType: ?Sized + NSFetchRequestResult> NSObjectProtocol
        for NSAsynchronousFetchRequest<ResultType>
    {
    }
);

#[cfg(feature = "NSPersistentStoreRequest")]
impl<ResultType: Message + NSFetchRequestResult> NSAsynchronousFetchRequest<ResultType> {
    extern_methods!(
        #[unsafe(method(fetchRequest))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchRequest(&self) -> Retained<NSFetchRequest<ResultType>>;

        #[cfg(all(feature = "NSPersistentStoreResult", feature = "block2"))]
        /// # Safety
        ///
        /// The returned block's argument must be a valid pointer.
        #[unsafe(method(completionBlock))]
        #[unsafe(method_family = none)]
        pub unsafe fn completionBlock(
            &self,
        ) -> NSPersistentStoreAsynchronousFetchResultCompletionBlock;

        #[unsafe(method(estimatedResultCount))]
        #[unsafe(method_family = none)]
        pub unsafe fn estimatedResultCount(&self) -> NSInteger;

        /// Setter for [`estimatedResultCount`][Self::estimatedResultCount].
        #[unsafe(method(setEstimatedResultCount:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEstimatedResultCount(&self, estimated_result_count: NSInteger);

        #[cfg(all(feature = "NSPersistentStoreResult", feature = "block2"))]
        #[unsafe(method(initWithFetchRequest:completionBlock:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithFetchRequest_completionBlock(
            this: Allocated<Self>,
            request: &NSFetchRequest<ResultType>,
            blk: Option<&block2::DynBlock<dyn Fn(NonNull<NSAsynchronousFetchResult<ResultType>>)>>,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "NSPersistentStoreRequest")]
impl<ResultType: Message + NSFetchRequestResult> NSAsynchronousFetchRequest<ResultType> {
    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>;
    );
}