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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

__inner_extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSFetchedResultsController<ResultType: ?Sized = AnyObject> {
        __superclass: NSObject,
        _inner0: PhantomData<*mut ResultType>,
        notunwindsafe: PhantomData<&'static mut ()>,
    }

    unsafe impl<ResultType: ?Sized + Message> ClassType for NSFetchedResultsController<ResultType> {
        type Super = NSObject;
        type Mutability = InteriorMutable;

        fn as_super(&self) -> &Self::Super {
            &self.__superclass
        }

        fn as_super_mut(&mut self) -> &mut Self::Super {
            &mut self.__superclass
        }
    }
);

unsafe impl<ResultType: ?Sized> NSObjectProtocol for NSFetchedResultsController<ResultType> {}

extern_methods!(
    unsafe impl<ResultType: Message> NSFetchedResultsController<ResultType> {
        #[cfg(all(
            feature = "NSFetchRequest",
            feature = "NSManagedObjectContext",
            feature = "NSPersistentStoreRequest"
        ))]
        #[method_id(@__retain_semantics Init initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:)]
        pub unsafe fn initWithFetchRequest_managedObjectContext_sectionNameKeyPath_cacheName(
            this: Allocated<Self>,
            fetch_request: &NSFetchRequest<ResultType>,
            context: &NSManagedObjectContext,
            section_name_key_path: Option<&NSString>,
            name: Option<&NSString>,
        ) -> Retained<Self>;

        #[method(performFetch:_)]
        pub unsafe fn performFetch(&self) -> Result<(), Retained<NSError>>;

        #[cfg(all(feature = "NSFetchRequest", feature = "NSPersistentStoreRequest"))]
        #[method_id(@__retain_semantics Other fetchRequest)]
        pub unsafe fn fetchRequest(&self) -> Retained<NSFetchRequest<ResultType>>;

        #[cfg(feature = "NSManagedObjectContext")]
        #[method_id(@__retain_semantics Other managedObjectContext)]
        pub unsafe fn managedObjectContext(&self) -> Retained<NSManagedObjectContext>;

        #[method_id(@__retain_semantics Other sectionNameKeyPath)]
        pub unsafe fn sectionNameKeyPath(&self) -> Option<Retained<NSString>>;

        #[method_id(@__retain_semantics Other cacheName)]
        pub unsafe fn cacheName(&self) -> Option<Retained<NSString>>;

        #[method_id(@__retain_semantics Other delegate)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSFetchedResultsControllerDelegate>>>;

        #[method(setDelegate:)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn NSFetchedResultsControllerDelegate>>,
        );

        #[method(deleteCacheWithName:)]
        pub unsafe fn deleteCacheWithName(name: Option<&NSString>);

        #[method_id(@__retain_semantics Other fetchedObjects)]
        pub unsafe fn fetchedObjects(&self) -> Option<Retained<NSArray<ResultType>>>;

        #[method_id(@__retain_semantics Other objectAtIndexPath:)]
        pub unsafe fn objectAtIndexPath(&self, index_path: &NSIndexPath) -> Retained<ResultType>;

        #[method_id(@__retain_semantics Other indexPathForObject:)]
        pub unsafe fn indexPathForObject(
            &self,
            object: &ResultType,
        ) -> Option<Retained<NSIndexPath>>;

        #[method_id(@__retain_semantics Other sectionIndexTitleForSectionName:)]
        pub unsafe fn sectionIndexTitleForSectionName(
            &self,
            section_name: &NSString,
        ) -> Option<Retained<NSString>>;

        #[method_id(@__retain_semantics Other sectionIndexTitles)]
        pub unsafe fn sectionIndexTitles(&self) -> Retained<NSArray<NSString>>;

        #[method_id(@__retain_semantics Other sections)]
        pub unsafe fn sections(
            &self,
        ) -> Option<Retained<NSArray<ProtocolObject<dyn NSFetchedResultsSectionInfo>>>>;

        #[method(sectionForSectionIndexTitle:atIndex:)]
        pub unsafe fn sectionForSectionIndexTitle_atIndex(
            &self,
            title: &NSString,
            section_index: NSInteger,
        ) -> NSInteger;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl<ResultType: Message> NSFetchedResultsController<ResultType> {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new() -> Retained<Self>;
    }
);

extern_protocol!(
    pub unsafe trait NSFetchedResultsSectionInfo {
        #[method_id(@__retain_semantics Other name)]
        unsafe fn name(&self) -> Retained<NSString>;

        #[method_id(@__retain_semantics Other indexTitle)]
        unsafe fn indexTitle(&self) -> Option<Retained<NSString>>;

        #[method(numberOfObjects)]
        unsafe fn numberOfObjects(&self) -> NSUInteger;

        #[method_id(@__retain_semantics Other objects)]
        unsafe fn objects(&self) -> Option<Retained<NSArray>>;
    }

    unsafe impl ProtocolType for dyn NSFetchedResultsSectionInfo {}
);

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSFetchedResultsChangeType(pub NSUInteger);
impl NSFetchedResultsChangeType {
    pub const NSFetchedResultsChangeInsert: Self = Self(1);
    pub const NSFetchedResultsChangeDelete: Self = Self(2);
    pub const NSFetchedResultsChangeMove: Self = Self(3);
    pub const NSFetchedResultsChangeUpdate: Self = Self(4);
}

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

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

extern_protocol!(
    pub unsafe trait NSFetchedResultsControllerDelegate: NSObjectProtocol {
        #[cfg(feature = "NSManagedObjectID")]
        #[optional]
        #[method(controller:didChangeContentWithDifference:)]
        unsafe fn controller_didChangeContentWithDifference(
            &self,
            controller: &NSFetchedResultsController,
            diff: &NSOrderedCollectionDifference<NSManagedObjectID>,
        );

        #[optional]
        #[method(controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:)]
        unsafe fn controller_didChangeObject_atIndexPath_forChangeType_newIndexPath(
            &self,
            controller: &NSFetchedResultsController,
            an_object: &AnyObject,
            index_path: Option<&NSIndexPath>,
            r#type: NSFetchedResultsChangeType,
            new_index_path: Option<&NSIndexPath>,
        );

        #[optional]
        #[method(controller:didChangeSection:atIndex:forChangeType:)]
        unsafe fn controller_didChangeSection_atIndex_forChangeType(
            &self,
            controller: &NSFetchedResultsController,
            section_info: &ProtocolObject<dyn NSFetchedResultsSectionInfo>,
            section_index: NSUInteger,
            r#type: NSFetchedResultsChangeType,
        );

        #[optional]
        #[method(controllerWillChangeContent:)]
        unsafe fn controllerWillChangeContent(&self, controller: &NSFetchedResultsController);

        #[optional]
        #[method(controllerDidChangeContent:)]
        unsafe fn controllerDidChangeContent(&self, controller: &NSFetchedResultsController);

        #[optional]
        #[method_id(@__retain_semantics Other controller:sectionIndexTitleForSectionName:)]
        unsafe fn controller_sectionIndexTitleForSectionName(
            &self,
            controller: &NSFetchedResultsController,
            section_name: &NSString,
        ) -> Option<Retained<NSString>>;
    }

    unsafe impl ProtocolType for dyn NSFetchedResultsControllerDelegate {}
);