objc2_core_data/generated/
NSFetchedResultsController.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/coredata/nsfetchedresultscontroller?language=objc)
12    #[unsafe(super(NSObject))]
13    #[derive(Debug, PartialEq, Eq, Hash)]
14    #[cfg(feature = "NSFetchRequest")]
15    pub struct NSFetchedResultsController<ResultType: ?Sized = AnyObject>;
16);
17
18#[cfg(feature = "NSFetchRequest")]
19impl<ResultType: ?Sized + Message + NSFetchRequestResult> NSFetchedResultsController<ResultType> {
20    /// Unchecked conversion of the generic parameter.
21    ///
22    /// # Safety
23    ///
24    /// The generic must be valid to reinterpret as the given type.
25    #[inline]
26    pub unsafe fn cast_unchecked<NewResultType: ?Sized + Message + NSFetchRequestResult>(
27        &self,
28    ) -> &NSFetchedResultsController<NewResultType> {
29        unsafe { &*((self as *const Self).cast()) }
30    }
31}
32
33#[cfg(feature = "NSFetchRequest")]
34extern_conformance!(
35    unsafe impl<ResultType: ?Sized + NSFetchRequestResult> NSObjectProtocol
36        for NSFetchedResultsController<ResultType>
37    {
38    }
39);
40
41#[cfg(feature = "NSFetchRequest")]
42impl<ResultType: Message + NSFetchRequestResult> NSFetchedResultsController<ResultType> {
43    extern_methods!(
44        #[cfg(all(
45            feature = "NSManagedObjectContext",
46            feature = "NSPersistentStoreRequest"
47        ))]
48        #[unsafe(method(initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:))]
49        #[unsafe(method_family = init)]
50        pub unsafe fn initWithFetchRequest_managedObjectContext_sectionNameKeyPath_cacheName(
51            this: Allocated<Self>,
52            fetch_request: &NSFetchRequest<ResultType>,
53            context: &NSManagedObjectContext,
54            section_name_key_path: Option<&NSString>,
55            name: Option<&NSString>,
56        ) -> Retained<Self>;
57
58        #[unsafe(method(performFetch:_))]
59        #[unsafe(method_family = none)]
60        pub unsafe fn performFetch(&self) -> Result<(), Retained<NSError>>;
61
62        #[cfg(feature = "NSPersistentStoreRequest")]
63        #[unsafe(method(fetchRequest))]
64        #[unsafe(method_family = none)]
65        pub unsafe fn fetchRequest(&self) -> Retained<NSFetchRequest<ResultType>>;
66
67        #[cfg(feature = "NSManagedObjectContext")]
68        #[unsafe(method(managedObjectContext))]
69        #[unsafe(method_family = none)]
70        pub unsafe fn managedObjectContext(&self) -> Retained<NSManagedObjectContext>;
71
72        #[unsafe(method(sectionNameKeyPath))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn sectionNameKeyPath(&self) -> Option<Retained<NSString>>;
75
76        #[unsafe(method(cacheName))]
77        #[unsafe(method_family = none)]
78        pub unsafe fn cacheName(&self) -> Option<Retained<NSString>>;
79
80        /// # Safety
81        ///
82        /// This is not retained internally, you must ensure the object is still alive.
83        #[unsafe(method(delegate))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn delegate(
86            &self,
87        ) -> Option<Retained<ProtocolObject<dyn NSFetchedResultsControllerDelegate>>>;
88
89        /// Setter for [`delegate`][Self::delegate].
90        ///
91        /// # Safety
92        ///
93        /// This is unretained, you must ensure the object is kept alive while in use.
94        #[unsafe(method(setDelegate:))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn setDelegate(
97            &self,
98            delegate: Option<&ProtocolObject<dyn NSFetchedResultsControllerDelegate>>,
99        );
100
101        #[unsafe(method(deleteCacheWithName:))]
102        #[unsafe(method_family = none)]
103        pub unsafe fn deleteCacheWithName(name: Option<&NSString>);
104
105        #[unsafe(method(fetchedObjects))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn fetchedObjects(&self) -> Option<Retained<NSArray<ResultType>>>;
108
109        #[unsafe(method(objectAtIndexPath:))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn objectAtIndexPath(&self, index_path: &NSIndexPath) -> Retained<ResultType>;
112
113        #[unsafe(method(indexPathForObject:))]
114        #[unsafe(method_family = none)]
115        pub unsafe fn indexPathForObject(
116            &self,
117            object: &ResultType,
118        ) -> Option<Retained<NSIndexPath>>;
119
120        #[unsafe(method(sectionIndexTitleForSectionName:))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn sectionIndexTitleForSectionName(
123            &self,
124            section_name: &NSString,
125        ) -> Option<Retained<NSString>>;
126
127        #[unsafe(method(sectionIndexTitles))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn sectionIndexTitles(&self) -> Retained<NSArray<NSString>>;
130
131        #[unsafe(method(sections))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn sections(
134            &self,
135        ) -> Option<Retained<NSArray<ProtocolObject<dyn NSFetchedResultsSectionInfo>>>>;
136
137        #[unsafe(method(sectionForSectionIndexTitle:atIndex:))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn sectionForSectionIndexTitle_atIndex(
140            &self,
141            title: &NSString,
142            section_index: NSInteger,
143        ) -> NSInteger;
144    );
145}
146
147/// Methods declared on superclass `NSObject`.
148#[cfg(feature = "NSFetchRequest")]
149impl<ResultType: Message + NSFetchRequestResult> NSFetchedResultsController<ResultType> {
150    extern_methods!(
151        #[unsafe(method(init))]
152        #[unsafe(method_family = init)]
153        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
154
155        #[unsafe(method(new))]
156        #[unsafe(method_family = new)]
157        pub unsafe fn new() -> Retained<Self>;
158    );
159}
160
161extern_protocol!(
162    /// [Apple's documentation](https://developer.apple.com/documentation/coredata/nsfetchedresultssectioninfo?language=objc)
163    pub unsafe trait NSFetchedResultsSectionInfo {
164        #[unsafe(method(name))]
165        #[unsafe(method_family = none)]
166        unsafe fn name(&self) -> Retained<NSString>;
167
168        #[unsafe(method(indexTitle))]
169        #[unsafe(method_family = none)]
170        unsafe fn indexTitle(&self) -> Option<Retained<NSString>>;
171
172        #[unsafe(method(numberOfObjects))]
173        #[unsafe(method_family = none)]
174        unsafe fn numberOfObjects(&self) -> NSUInteger;
175
176        #[unsafe(method(objects))]
177        #[unsafe(method_family = none)]
178        unsafe fn objects(&self) -> Option<Retained<NSArray>>;
179    }
180);
181
182/// [Apple's documentation](https://developer.apple.com/documentation/coredata/nsfetchedresultschangetype?language=objc)
183// NS_ENUM
184#[repr(transparent)]
185#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
186pub struct NSFetchedResultsChangeType(pub NSUInteger);
187impl NSFetchedResultsChangeType {
188    #[doc(alias = "NSFetchedResultsChangeInsert")]
189    pub const Insert: Self = Self(1);
190    #[doc(alias = "NSFetchedResultsChangeDelete")]
191    pub const Delete: Self = Self(2);
192    #[doc(alias = "NSFetchedResultsChangeMove")]
193    pub const Move: Self = Self(3);
194    #[doc(alias = "NSFetchedResultsChangeUpdate")]
195    pub const Update: Self = Self(4);
196}
197
198unsafe impl Encode for NSFetchedResultsChangeType {
199    const ENCODING: Encoding = NSUInteger::ENCODING;
200}
201
202unsafe impl RefEncode for NSFetchedResultsChangeType {
203    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
204}
205
206extern_protocol!(
207    /// [Apple's documentation](https://developer.apple.com/documentation/coredata/nsfetchedresultscontrollerdelegate?language=objc)
208    pub unsafe trait NSFetchedResultsControllerDelegate: NSObjectProtocol {
209        #[cfg(all(feature = "NSFetchRequest", feature = "NSManagedObjectID"))]
210        /// # Safety
211        ///
212        /// `controller` generic should be bound by `NSFetchRequestResult`.
213        #[optional]
214        #[unsafe(method(controller:didChangeContentWithDifference:))]
215        #[unsafe(method_family = none)]
216        unsafe fn controller_didChangeContentWithDifference(
217            &self,
218            controller: &NSFetchedResultsController,
219            diff: &NSOrderedCollectionDifference<NSManagedObjectID>,
220        );
221
222        #[cfg(feature = "NSFetchRequest")]
223        /// # Safety
224        ///
225        /// - `controller` generic should be bound by `NSFetchRequestResult`.
226        /// - `an_object` should be of the correct type.
227        #[optional]
228        #[unsafe(method(controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:))]
229        #[unsafe(method_family = none)]
230        unsafe fn controller_didChangeObject_atIndexPath_forChangeType_newIndexPath(
231            &self,
232            controller: &NSFetchedResultsController,
233            an_object: &AnyObject,
234            index_path: Option<&NSIndexPath>,
235            r#type: NSFetchedResultsChangeType,
236            new_index_path: Option<&NSIndexPath>,
237        );
238
239        #[cfg(feature = "NSFetchRequest")]
240        /// # Safety
241        ///
242        /// `controller` generic should be bound by `NSFetchRequestResult`.
243        #[optional]
244        #[unsafe(method(controller:didChangeSection:atIndex:forChangeType:))]
245        #[unsafe(method_family = none)]
246        unsafe fn controller_didChangeSection_atIndex_forChangeType(
247            &self,
248            controller: &NSFetchedResultsController,
249            section_info: &ProtocolObject<dyn NSFetchedResultsSectionInfo>,
250            section_index: NSUInteger,
251            r#type: NSFetchedResultsChangeType,
252        );
253
254        #[cfg(feature = "NSFetchRequest")]
255        /// # Safety
256        ///
257        /// `controller` generic should be bound by `NSFetchRequestResult`.
258        #[optional]
259        #[unsafe(method(controllerWillChangeContent:))]
260        #[unsafe(method_family = none)]
261        unsafe fn controllerWillChangeContent(&self, controller: &NSFetchedResultsController);
262
263        #[cfg(feature = "NSFetchRequest")]
264        /// # Safety
265        ///
266        /// `controller` generic should be bound by `NSFetchRequestResult`.
267        #[optional]
268        #[unsafe(method(controllerDidChangeContent:))]
269        #[unsafe(method_family = none)]
270        unsafe fn controllerDidChangeContent(&self, controller: &NSFetchedResultsController);
271
272        #[cfg(feature = "NSFetchRequest")]
273        /// # Safety
274        ///
275        /// `controller` generic should be bound by `NSFetchRequestResult`.
276        #[optional]
277        #[unsafe(method(controller:sectionIndexTitleForSectionName:))]
278        #[unsafe(method_family = none)]
279        unsafe fn controller_sectionIndexTitleForSectionName(
280            &self,
281            controller: &NSFetchedResultsController,
282            section_name: &NSString,
283        ) -> Option<Retained<NSString>>;
284    }
285);